【问题标题】:JavaScript - IE8 window.onload() is not working in new opened windowJavaScript - IE8 window.onload() 在新打开的窗口中不起作用
【发布时间】:2011-03-24 14:36:59
【问题描述】:

这篇文章与window.onload() is not firing with IE 8 in first shot相关。

从主页(窗口)中打开一个新窗口:

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

新窗口已正确打开,但 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>

用 Prototype 的“document.observe('dom:loaded', function()”和 body-Tag 中的“onload”属性替换“window.onload”也不起作用。如果我重新加载内容新打开的窗口或再次打开它,然后代码工作正常。如果我从主窗口中运行代码,那么代码也工作正常。这似乎是一个缓存问题,但我不确定。

我的 IE 版本是 8.0.6001.18702。我已经推迟了所有的附加组件。

在此先感谢

【问题讨论】:

  • 抱歉,有点不清楚。 window.open('foobar.php');上面的代码位于'foobar.php'。
  • 请发布window.open的确切代码。

标签: javascript internet-explorer-8 window.open


【解决方案1】:

由于脚本在已经加载的页面中,onload 事件发生在很久以前。

窗口加载的时间和 DOM 准备好的时间是有区别的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-30
    相关资源
    最近更新 更多