![](/img/trans.png)
[英]Writing to the DOM on body onload not working in Google Chrome
[英]google chrome iframe body onLoad not working?
編輯:它確實有效(抱歉)。 此腳本中的某些內容導致它在谷歌瀏覽器中停止:
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 更改以顯示不同的頁面。 在其中一個頁面上,我有一個腳本被加載到 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.");
}
感謝您的關注。
原來它只是一個安全例外
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.
一旦上線,應該沒問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.