Permission denied to access property document '

I use the following script there, form this script on my page, add an iframe, and I want to get an iframe html.

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

The problem in the iframe is the internal iframe.

Javascript function used to get ifrmae content

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

When I run this, the following error will be displayed

 Permission denied to access property 'document' 

How to solve the problem of access denied.

+4
javascript jquery php iframe
source share
3 answers

You can not.

Why? This is a security feature to prevent Cross-Site Scripting (XSS) attacks.

For example, you have an iframe that loads www.facebook.com . If this security feature has not been implemented, you can easily retrieve data from this site. From cookies, what content is on the page.

There is more useful information here: http://www.veracode.com/security/xss

+3
source share

I have not looked at JS, but you cannot get HTML from a remote page with javascript. Try PHP cURL.

+1
source share

Try

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

Source: Frame / IFrame contentDocument property .

-2
source share

All Articles