【问题标题】:google chrome iframe body onLoad not working?谷歌浏览器 iframe 正文 onLoad 不起作用?
【发布时间】:2012-04-21 06:04:54
【问题描述】:

编辑:它确实有效(抱歉)。此脚本中的某些内容导致它在 google chrome 中停止:

function checkLocation() {
  var loc = top.location.href;
  var suffix = "subpage.html";
  if (loc.indexOf(suffix, loc.length - suffix.length) !== -1) {
      top.location.href = "index.html";
  }
}

原帖:

我已经安装了 IE 9、FF 3.6.3、Chrome (18.0.1025.151) 和 Safari 5.1.5。

这适用于除谷歌浏览器之外的所有浏览器。

我有一个包含命名 iframe 的 HTML 布局。 iframe src 更改以显示不同的页面。在其中一个页面上,我有一个在 body 标记中加载 onLoad 的脚本。当页面仅在谷歌浏览器的 iframe 中加载时,此脚本不会加载 - 它在其他浏览器中运行良好。另外,如果我将页面直接加载到谷歌浏览器中(而不是通过 iframe),它就可以正常工作。

我该如何解决这个问题?

这是一个示例代码:

index.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html> <head> <title> Example Page </title> </head>
       <body> <a href="subpage.html" target="targetFrame">View subpage</a><BR/>
              <iframe name="targetFrame"> </iframe>
       </body>
</html>

subpage.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html> <head> <title> Subpage </title>
              <script type="text/javascript" src="subpage.js"> </script>
       </head>
       <body onLoad="initialise()"> Hello </body>
</html>

subpage.js
function initialise() {
    alert("Script loaded.");
}

感谢收看。

【问题讨论】:

    标签: javascript google-chrome iframe onload


    【解决方案1】:

    原来它只是一个安全例外

    Unsafe JavaScript attempt to access frame
    with URL file:///C:/Users/.../website/index.html
    from frame
    with URL file:///C:/Users/.../website/subfolder/subpage.html.
    Domains, protocols and ports must match.
    

    一旦上线就应该没问题了。

    【讨论】:

      猜你喜欢
      • 2011-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-15
      • 2018-12-07
      • 2015-06-16
      • 2020-04-11
      • 1970-01-01
      相关资源
      最近更新 更多