im trying to set the height of two divs on my page, because my page content is dynamic. But it wont work. The height is just one screen of the divs.
The divs contain side borders, thats why it has to be all the way. Any ideas why the height only = one screen height?
function bodyHeight() {
var scnHei;
if (self.innerHeight) // all except Explorer
{
scnHei = self.innerHeight;
}
else if (document.documentElement && document.documentElement.clientHeight)
// Explorer 6 Strict Mode
{
scnHei = document.documentElement.clientHeight;
}
else if (document.body) // other Explorers
{
scnHei = document.body.clientHeight;
}
document.getElementById("bgr_right").style.height=scnHei + "px";
document.getElementById("bgr_left").style.height=scnHei + "px";
}
Here is where I call the function:
<body onload="bodyHeight();">
UPDATE: + added "px"; but DOESNT WORK EITHER...
im trying to set the height of two divs on my page, because my page content is dynamic. But it wont work. The height is just one screen of the divs.
The divs contain side borders, thats why it has to be all the way. Any ideas why the height only = one screen height?
function bodyHeight() {
var scnHei;
if (self.innerHeight) // all except Explorer
{
scnHei = self.innerHeight;
}
else if (document.documentElement && document.documentElement.clientHeight)
// Explorer 6 Strict Mode
{
scnHei = document.documentElement.clientHeight;
}
else if (document.body) // other Explorers
{
scnHei = document.body.clientHeight;
}
document.getElementById("bgr_right").style.height=scnHei + "px";
document.getElementById("bgr_left").style.height=scnHei + "px";
}
Here is where I call the function:
<body onload="bodyHeight();">
UPDATE: + added "px"; but DOESNT WORK EITHER...
Share Improve this question edited Oct 26, 2009 at 14:14 asked Oct 26, 2009 at 14:03 user188962user188962 1- Can you add an alert to confirm that the document/body has a valid Height? – donohoe Commented Oct 26, 2009 at 14:30
3 Answers
Reset to default 3.style.height=scnHei;
should rather be
.style.height=scnHei + "px";
The same goes for .style.width
of course. You forgot to add the unit to the width / height value.
This is only firing once, when the body is loaded. If you have an event that makes another call to BodyHeight();
then this should work.
Height and width properties require a unit (either "%" or "px"). Try this:
.style.height = scnHei + "px";
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745096521a4611010.html
评论列表(0条)