aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/javascript/reference/errors/property_access_denied/index.html
blob: 7b90b8be6f0b12a7f5dd126ec4149cafd7e9c75e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
---
title: 'Error: Permission denied to access property "x"'
slug: Web/JavaScript/Reference/Errors/Property_access_denied
tags:
  - Error
  - Permission denied
  - 错误
translation_of: Web/JavaScript/Reference/Errors/Property_access_denied
---
<div>{{jsSidebar("Errors")}}</div>

<h2 id="消息">消息</h2>

<pre class="syntaxbox">Error: Permission denied to access property "x"
</pre>

<h2 id="错误类型">错误类型</h2>

<p>{{jsxref("Error","错误")}}.</p>

<h2 id="什么地方出错了">什么地方出错了?</h2>

<p>尝试访问无权访问的对象。这很可能出现在使用{{HTMLElement("iframe")}}元素时加载了一个不同域名下的页面,这在访问子页面时会违背<a href="/zh-CN/docs/Web/Security/Same-origin_policy">同源策略</a></p>

<h2 id="示例">示例</h2>

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

<p>可以参考</p>

<ul>
 <li>{{HTMLElement("iframe")}}</li>
 <li><a href="/zh-CN/docs/Web/Security/Same-origin_policy">同源策略</a></li>
</ul>