谷歌浏览器iframe身体加载不工作

google chrome iframe body onLoad not working?

本文关键字:工作 加载 iframe 谷歌浏览器      更新时间:2023-09-26

编辑:它确实有效(对不起)。此脚本中的某些内容导致它在谷歌浏览器中停止:

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 将更改为显示不同的页面。在其中一个页面上,我有一个脚本,该脚本在正文标签中加载。此脚本仅在谷歌浏览器的 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.");
}

谢谢你的关注。

原来这只是一个安全异常

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.

一旦上线,应该没问题。