KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have a situation where I have web apps on two different servers, where App1 contains App2 in an IFrame. Any links in App2 can have target="_parent" attribute, which allow those links to open in the top window. However, I can't find any way to get the same behavior in Javascript. I found this page , which claims that the child frame can call javascript on the parent frame using parent.foo() , but that doesn't seem to work in IE8 or FF3.5. I found this SO question which explains how this security model works. But it seems odd that I can't do in Javascript what I can do with a simple <a> tag. Is there any workaround to this at all? I know about window.postMessage , but (as far as I know) this only works in Firefox. Example server1/test.html <html> <head> <script type="text/javascript"> function myCallback(foo) { alert(foo); } </script> </head> <body> <iframe src="http://server2/test2.htm" width="400" height="150"></iframe> </body></html> server2/test2.html <html><body> <script> function clickit() { parent.document.location = "http://www.google.com"; //not allowed parent.myCallback("http://www.google.com"); //not allowed } </script> <p>This should be in an iFrame!</p> <p><a href="http://www.google.com" target="_parent">normal link (works)</a></p> <p><a href="javascript:clickit()">javascript link</a></p> </body></html>
Tags (comma-separated)
Save Edits
Cancel