问题描述
我在网站上有以下代码:
window.onload = resize;
window.onresize = resize;
function resize(){
heightWithoutHeader = (window.innerHeight - 85) + "px";
document.getElementById("main-table").style.height = heightWithoutHeader;
document.getElementById("navigation").style.height = heightWithoutHeader;
}
onresize
可以正常工作,但是onload
事件永远不会触发.我已经在Firefox和Chrome浏览器中尝试过了,但它们都不起作用.
感谢您的帮助并赢得声誉! ; D
我认为这里可能发生的事是您的window.onload
稍后将被覆盖,请检查以确保它不是通过<body onload="">
您可以在调整大小功能中按alert(window.onload)
进行检查,以查看其中实际附加的内容.
I've got the following code in a website:
window.onload = resize;
window.onresize = resize;
function resize(){
heightWithoutHeader = (window.innerHeight - 85) + "px";
document.getElementById("main-table").style.height = heightWithoutHeader;
document.getElementById("navigation").style.height = heightWithoutHeader;
}
The onresize
works fine, but the onload
event never fires. I've tried it in Firefox and Chrome and neither of them works.
Thank you for your help and go for the reputation! ;D
I think what's probably happening here is that your window.onload
is being overridden later, check to make sure that it's not via things like <body onload="">
You can check this by alert(window.onload)
in your re-size function, to see what's actually attached there.
这篇关于JavaScript事件window.onload未触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!