Estoy tratando de escribir una secuencia de comandos para cambiar el ancho de la página, teniendo en cuenta el ancho del cliente del usuario. es algo como esto:Cambiar el estilo de etiqueta de cuerpo a través de JavaScript
function adjustWidth() {
width = 0;
if (window.innerHeight) {
width = window.innerWidth;
} else if (document.documentElement && document.documentElement.clientHeight) {
width = document.documentElement.clientWidth;
} else if (document.body) {
width = document.body.clientWidth;
}
if (width < 1152) {
document.getElementsByTagName("body").style.width="950px";
}
if (width >= 1152) {
document.getElementsByTagName("body").style.width="1075px";
}
}
window.onresize = function() {
adjustWidth();
};
window.onload = function() {
adjustWidth();
};
Con este guión me sale un error de Firebug:
document.getElementsByTagName("body").style is undefined
Ahora mi pregunta es, ¿cómo puedo acceder al estilo de cuerpo? Porque en la hoja de css se definen su propiedad de selector y ancho.
try ** 'getComputedStyle (elementos) [estilo]' ** y el ejemplo ** 'window.getComputedStyle (document.body) .width' ** .. . aprender http://javascript.info/tutorial/styles-and-classes-getcomputedstyle – KingRider