问题
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