错误:访问属性 "x" 的权限被拒绝

当尝试访问你无权访问的对象时,会出现 JavaScript 异常 "访问属性的权限被拒绝"。

¥The JavaScript exception "Permission denied to access property" occurs when there was an attempt to access an object for which you have no permission.

信息

¥Message

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)

错误类型

¥Error type

DOMException

什么地方出了错?

¥What went wrong?

试图访问你无权访问的对象。这可能是从违反 同源策略 的不同域加载的 <iframe> 元素。

¥There was attempt to access an object for which you have no permission. This is likely an <iframe> element loaded from a different domain for which you violated the same-origin policy.

示例

¥Examples

无权访问文档

¥No permission to access document

html
<!doctype html>
<html lang="en-US">
  <head>
    <iframe
      id="myframe"
      src="http://www1.w3c-test.org/common/blank.html"></iframe>
    <script>
      onload = function () {
        console.log(frames[0].document);
        // Error: Permission denied to access property "document"
      };
    </script>
  </head>
  <body></body>
</html>

也可以看看