JavaScript事件window.onload未触发 [英] JavaScript event window.onload not triggered

查看:210
本文介绍了JavaScript事件window.onload未触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网站上有以下代码:

 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未触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆