Error: Permission denied to access property "x"

當您嘗試訪問一個沒有許可權的物件時,會發生 JavaScript 異常“訪問屬性的許可權被拒絕”。

訊息

DOMException: Blocked a frame with origin "x" from accessing a cross-origin frame. (Chromium-based)
DOMException: Permission denied to access property "x" on cross-origin object (Firefox)
SecurityError: Blocked a frame with origin "x" from accessing a cross-origin frame. Protocols, domains, and ports must match. (Safari)

錯誤型別

DOMException.

哪裡出錯了?

嘗試訪問您沒有許可權的物件。這可能是一個從不同域載入的 <iframe> 元素,您違反了同源策略

示例

沒有訪問文件的許可權

html
<iframe id="myframe" src="http://www1.w3c-test.org/common/blank.html"></iframe>
js
console.log(frames[0].document);
// Error: Permission denied to access property "document"

另見