google chrome iframe body onLoad无法正常工作?

时间:2012-04-08 14:23:47

标签: javascript google-chrome iframe onload

编辑:它确实有用(抱歉)。此脚本中的某些内容导致它在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.");
}

感谢您的光临。

1 个答案:

答案 0 :(得分:0)

原来只是一个安全例外

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.

一旦上线就应该没问题。

相关问题