Permission denied to access property 'document' [duplicate]

♀尐吖头ヾ 提交于 2019-12-31 00:08:51

问题


I am using following script there, form this script on my page add iframe and I want to get iframe html.

<script src="http://ads.sonobi.com/ttj?id=881134" type="text/javascript"></script> 

Problem is in iframe there is inner iframe.

Javascript following function using for get content of ifrmae

document.getElementById('f1').contentWindow.document.body.innerHTML 

When I run this will show following error

Permission denied to access property 'document'

How to solve the problem of permission denied.


回答1:


You can't.

Why? It's a security feature to stop Cross-Site Scripting (XSS) attacks.

For example, you have an iframe that loads www.facebook.com. If this security feature wasn't implemented, you could easily fetch data from that site. From cookies, to what content is on the page.

There is more helpful information about this here: http://www.veracode.com/security/xss




回答2:


I didn't look at the JS, but you can't get HTML from an remote page with javascript. Try PHP's cURL.




回答3:


Try

var frame = document.getElementById('f1');
var doc = frame.contentWindow || frame.contentDocument;
var html = doc.document.body.innerHTML

Source: Frame/IFrame contentDocument Property.



来源:https://stackoverflow.com/questions/13758708/permission-denied-to-access-property-document

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!