【问题标题】:Getting Permission denied to access property "document"获得拒绝访问属性“文档”的权限
【发布时间】:2016-07-14 01:34:04
【问题描述】:

我不清楚为什么在从不同域I have not set any X-Frame-Options header in the HTTP response 的网络浏览器中加载 HTML 文件时出现此错误

访问属性“文档”的权限被拒绝

这是我的服务器头信息

curl -I zariga.com

输出

  HTTP/1.1 200 OK
Date: Wed, 13 Jul 2016 17:17:57 GMT
Server: Apache-Coyote/1.1
Content-Type: text/html;charset=UTF-8
Transfer-Encoding: chunked
Set-Cookie: JSESSIONID=656D65705C14A5B643B6EA281DF03A8D; Path=/
Vary: Accept-Encoding

我的 HTML iFrame 文件

<html>
<script>

function myFunction() {

    document.domain = "zariga.com";

var i = document.createElement('iframe');

i.setAttribute('id', 'i');
i.setAttribute('style', 'visibility:hidden;width:0px;height:0px;');
i.setAttribute('src', 'http://www.zariga.com/');
i.onload = function(){
alert(i.contentWindow.document.getElementsByName('syc')[0].value);
 alert(2);
};

document.body.appendChild(i);

}

</script>
<body>
<button onclick="myFunction()">Try it</button>
</body>

</html>

【问题讨论】:

  • 当前的 document.domain 是什么?你能在浏览器控制台中检查一下吗?

标签: javascript html iframe


【解决方案1】:

您无法通过这种方式访问​​ iframe 的内容。否则,您很容易注入其他网站并窃取访问者的帐户。

如果您可以访问包含在 iframe 中的网站,您可以让它向包含它的页面发送消息。iframe 中的 window.parent 将等同于主页中的 window。

所以要发回一个值,请将此代码添加到主页:

function childCallback(value) {

}

这个到 iframe 中的页面:

parent.childCallback(document.getElementsByName('syc')[0].value);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-04-24
    • 1970-01-01
    • 1970-01-01
    • 2017-02-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多