views:

613

answers:

2

I have an iframe being created on a page, and the page's domain is being explicitly set to 'xyz.com' but the iframe's domain is defaulting to 'dev.xyz.com', which is the actual domain i'm developing for.

The problem is, when I try to access that iframe via iframe.contentWindow.document, it fails due to the difference in domain.

I've tried setting the iframe's src to a file with document.domain = 'xyz.com' but that doesn't seem to be doing the trick...

Any ideas?

+1  A: 

I believe you need to set both the iframe's document.domain and the main page's document.domain to the same thing. (more info here)

Alconja
+2  A: 

Page inside iframe:

<script>
document.domain = document.domain;
</script>

It looks silly, but it works.

NV