Forum Moderators: open

Message Too Old, No Replies

Allow javascript access from iframe with remote content

iframe content loaded from remote domain

         

Mike521

8:36 pm on Jul 20, 2009 (gmt 0)

10+ Year Member



Hi all, I'm trying to allow javascript access for an iframe that's loading content on another domain.

so say my page is example.com/page.htm, and it has an iframe like:

iframe src='otherExample.com/otherPage.htm'

I want to run a javascript on otherPage.htm that has access to the contents of example.com/page.htm.

It seems like there's a block built into javascript to stop this from happening. If I load the page from my own domain it will have full access to the parent page (using things like document.top, top.document, etc). But if I load the same page from a remote domain, it thinks the top document is itself, it won't see the container page.

Is there a workaround? Something rings a bell about this being for security purposes

daveVk

5:24 am on Jul 21, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The 'same origin' policy will prevent you doing this. The surest workaround is to have the server ( example.com ) read the page from otherExample.com and forward it. Search for "cross domain ajax" for other ways, you will need cooperation from otherExample.com.

Mike521

2:57 pm on Jul 21, 2009 (gmt 0)

10+ Year Member



hmm I had a feeling it was something about security. I'd looked into JSON and JSONP through JQuery a while back but I didn't fall in love with the system. Seems like a PHP or ASP proxy will be the easiest solution

thanks dave