Can javascript access the iframe elements from the parent page?

I have an iframe on the page, the iframe and the parent page are in a different domain, can javascript code on the parent page access elements inside this iframe?

+6
javascript jquery html
source share
6 answers

It is impossible if the pages are from different domains, an isolated browser security environment should prevent this type of access. This can work when two pages are from different subdomains of the same domain, but it can and will differ between browsers (and possibly even versions of the same browser).

Access to the child iframe may work, but, on the contrary, will not work.

+12
source share

The easiest way is through the frames object in the window:

window.frames[0].document.getElementById('ElementId').style.backgroundColor="#000"; 
+3
source share

If the two domains are completely separated, then it’s impossible

+1
source share

This can be done using Chrome with the option --disable-web-security ...;)

+1
source share

Use jQuery.postMessage plugin http://benalman.com/code/projects/jquery-postmessage/docs/files/jquery-ba-postmessage-js.html

Browsers tested Internet Explorer 6-8, Firefox 3, Safari 3-4, Chrome, Opera 9.

+1
source share

Yes, through the document.frames array you can access iframes.

-2
source share

All Articles