Feb 03 2009
Javascript : Iframe : Cross domain scripting
Probelm :- Your page with domainA.com has an iFrame of domainB.com. You have some task, that needs you to call a javascript function in main page (domainA.com) from iFrame (domainB.com).
Hack :- I googled and found two solutions, both work for most common browsers but both have some limitations. ( Obiously its a security issue )
- First one I found at pipwerks. For it to work you must have access to web directory of parent frame (domainA). You need to upload a file there (proxy.html). According to it, you can put nested iframe from domainA into domainB. And call a function from this iframe instead, using top.functionName
- Other hack is from tagneto. To use this, you need to change parent.location adding a hash(#) to it. This won’t reload the page and hence it works. Here is a test page as well. See the source of test page and embedded iframe to check how it works.
If you know about any others? Lemme know.
Update :- approach 2 has some issues with IE7, its fixed here.
Tags: crossdomain, javascript, web development