×

JS报错“Error: Permission denied to access property "x"”的处理方法

作者:andy0012020.04.15来源:Web前端之家浏览:11328评论:0
关键词:jserro

我们运行程序的时候,有时候会出现报错,比如:Error: Permission denied to access property "x"。

什么地方出错了?

尝试访问无权访问的对象。这很可能出现在使用<iframe>元素时加载了一个不同域名下的页面,这在访问子页面时会违背同源策略。

示例

<!DOCTYPE html><html>
  <head>
    <iframe id="myframe" src="http://www1.w3c-test.org/common/blank.html"></iframe>
    <script>
      console.log(document.getElementById('myframe').contentWindow.document);
      // Error: Permission denied to access property "document"
    </script>
  </head>
  <body>
  </body>
</html>

您的支持是我们创作的动力!
温馨提示:本文作者系 ,经Web前端之家编辑修改或补充,转载请注明出处和本文链接:
https://www.jiangweishan.com/article/js88089sdjflkjsdklfjklj.html

网友评论文明上网理性发言 已有0人参与

发表评论: