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"

另见