HTML父窗口和iFrame內容相互瞭解,並且當它們位於同一個Web服務器上時可以自由通信。當他們被保存到DVD時,當iFrame嘗試以本地文件的形式聯繫top時,Chrome會拋出「不安全的JavaScript嘗試訪問帶有URL的幀」。如何在「不安全的JavaScript嘗試訪問帶有URL的框架」之前測試瀏覽器的權限(Chrome本地框架)?
下面的catch捕獲權限錯誤,但錯誤仍然由瀏覽器註冊並且對用戶可見。
如果在嘗試訪問之前允許訪問以排除不安全的JavaScript錯誤,是否有可能首先進行測試?
// Called from script in an iframe
function findSiblingIFrame(sibId) {
try {
var sibFrame = top.document.getElementById(sibId);
if (sibFrame != null) {
alert("found sibling iframe");
} else {
alert("did not find sibling iframe");
}
}
catch (err) {
alert("not allowed to find sibling iframe");
// Would rather test if permission first to prevent
// browser from registering the error.
}
}
查看http://www.netomatix.com/development/webcaspermissions.aspx。它可能會或可能不會幫助您作爲起點。 – MethodMan
感謝您的鏈接,但檢查瀏覽器權限級別對此情況無效。我正在尋找一種乾淨的方式來確定父級是否與孩子在同一個域中,而不必通過parent.location.xyz調用產生跨站點腳本錯誤。就好像不得不在爐子上放一隻手來測試爐子是否很熱。這只是不舒服的解釋,FireFox放在瀏覽器頁面上的大紅色ERROR ON PAGE圖標意味着代碼正常工作。 – spiraleddy