错误:拒绝访问属性“x”
当尝试访问您没有权限的对象时,会出现JavaScript异常“拒绝访问属性”。
消息
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)
错误类型
哪里出错了?
示例
没有访问文档的权限
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>