2012-04-08 97 views
0

编辑:它工作(对不起)。东西在这个脚本导致其停止在谷歌浏览器:谷歌铬iframe正文onLoad不工作?

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全部安装。

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

我有一个HTML布局,其中包含一个名为iframe。 iframe src更改为显示不同的页面。在其中一个页面上,我在脚本中加载了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."); 
} 

感谢您寻找。

回答

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. 

一旦其在线应该罚款。