Javascript problem: Works in FF but not in Chrome and Safari
Hi this is my code which I use on one div in order to automatically set its height to window one. The script works great in Firefox but not in Chrome or Safari. I tried few methods to fix it including some from previous posters but without effect, unfortunatelly. I think that the problem is hiding somewhere in document.getElementById("ID").style.height
but I am not completely sure. I will be glad if someone can help. Thanks in advance! :)
window.onload = Resize;
window.onresize = Resize;
function Resize() {
if (document.documentElement.scrollHeight === document.documentElement.clientHeight)
{
document.getElementByI开发者_JS百科d("ID").style.height = (window.innerHeight-220) + "px";
}
};
try this
function getHeight() {
var myHeight = 0;
if (typeof(window.innerHeight) == 'number') {
//Non-IE
myHeight = window.innerHeight;
} else if (document.documentElement && document.documentElement.clientHeight) {
//IE 6+ in 'standards compliant mode'
myHeight = document.documentElement.clientHeight;
} else if (document.body && document.body.clientHeight) {
//IE 4 compatible
myHeight = document.body.clientHeight;
}
return myHeight;
}
function getScrollY() {
var scrOfY = 0;
if (typeof(window.pageYOffset) == 'number') {
//Netscape compliant
scrOfY = window.pageYOffset;
} else if (document.body && document.body.scrollTop) {
//DOM compliant
scrOfY = document.body.scrollTop;
} else if (document.documentElement && document.documentElement.scrollTop) {
//IE6 standards compliant mode
scrOfY = document.documentElement.scrollTop;
}
return scrOfY;
}
function Resize() {
document.getElementById("ID").style.height = Math.round(getHeight() + getScrollY()) + "px";
}
window.onload = Resize();
window.onresize = Resize();
This will set the height of the ID to the height of the browser window + the vertical scroll offset.
精彩评论