简体   繁体   English

JavaScript-IE8 window.onload()在新打开的窗口中不起作用

[英]JavaScript - IE8 window.onload() is not working in new opened window

this post is related to window.onload() is not firing with IE 8 in first shot . 这篇文章与window.onload()有关, 第一枪未使用IE 8触发

From within the main page (window) I open a new window: 从主页(窗口)中,我打开一个新窗口:

... window.open('foobar.php',<...>); ...

The new window is opened correctly but the code within the window.onload() section (located in 'foobar.php') is not executed: 新窗口已正确打开,但是window.onload()节(位于“ foobar.php”中)中的代码未执行:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
   <title>foobar</title>
   <script type="text/javascript">
   //<![CDATA[
   window.onload = function ()
   {
      alert('foobar');
   }
   //]]>
   </script>
</head>
<body>
</body>
</html>

The replacement of "window.onload" by Prototype's "document.observe('dom:loaded', function()" and the "onload" attribute in the body-Tag do not work, too. If I reload the content of the new opened window or open it again then the code is working correctly. If I run the code from within the main window then the code is working correctly, too. It seems to be a caching problem but I'm not sure. 如果Prototype的“ document.observe('dom:loaded',function()”和body-Tag中的“ onload”属性替代了“ window.onload”,也无法工作。如果我重新加载新内容打开窗口或再次打开它,代码将正常工作;如果我从主窗口中运行代码,则代码也将正常工作。这似乎是一个缓存问题,但我不确定。

My IE version is 8.0.6001.18702. 我的IE版本是8.0.6001.18702。 I have put off all Add-Ons. 我推迟了所有加载项。

Many thanks in advance 提前谢谢了

Since the script is in the page that was ALREADY LOADED, the onload event happened long ago. 由于脚本位于已加载的页面中,因此onload事件发生在很久以前。

There is a difference between when the window has loaded and when the DOM is ready. 窗口加载时间与DOM准备时间之间存在差异。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM