uTools-Manuals/docs/javascript/Reference/Errors/Property_access_denied.html
2019-04-21 11:50:48 +08:00

28 lines
1.8 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<article id="wikiArticle">
<div></div>
<h2 id="消息">消息</h2>
<pre><code class="language-javascript">Error: Permission denied to access property "x"
</code></pre>
<h2 id="错误类型">错误类型</h2>
<p><a href="Reference/Global_Objects/Error" title="通过Error的构造器可以创建一个错误对象。当运行时错误产生时Error的实例对象会被抛出。Error对象也可用于用户自定义的异常的基础对象。下面列出了各种内建的标准错误类型。"><code>错误</code></a>.</p>
<h2 id="什么地方出错了">什么地方出错了?</h2>
<p>尝试访问无权访问的对象。这很可能出现在使用<a href="/zh-CN/docs/Web/HTML/Element/iframe" title="HTML内联框架元素 &lt;iframe&gt; 表示嵌套的浏览上下文有效地将另一个HTML页面嵌入到当前页面中。"><code>&lt;iframe&gt;</code></a>元素时加载了一个不同域名下的页面,这在访问子页面时会违背<a href="/zh-CN/docs/Web/Security/Same-origin_policy">同源策略</a></p>
<h2 id="示例">示例</h2>
<pre><code class="language-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;
</code></pre>
<p>可以参考</p>
<ul>
<li><a href="/zh-CN/docs/Web/HTML/Element/iframe" title="HTML内联框架元素 &lt;iframe&gt; 表示嵌套的浏览上下文有效地将另一个HTML页面嵌入到当前页面中。"><code>&lt;iframe&gt;</code></a></li>
<li><a href="/zh-CN/docs/Web/Security/Same-origin_policy">同源策略</a></li>
</ul>
</article>