--- 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 ---
Error: Permission denied to access property "x"
{{jsxref("Error","错误")}}.
尝试访问无权访问的对象。这很可能出现在使用{{HTMLElement("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>
可以参考