[GIS] Map in an iFrame – open hyperlink from infoWindow in the calling page

domainsgoogle mapshtmljavascript

I've got a Google Map being served inside an iFrame on a page (eg xxx.com/PageWithMap.html)

The code for the Google map sits on another domain (eg yyy.com/MapCode.html)

So it looks like this on xxx.com/PageWithMap.html:

<iframe src="yyy.com/MapCode.html"></iframe>

The markers in the map show an infoWindow which contains a hyperlink to a new page on the first site (eg <a href="xxx.com/photo1.html">photo link</a>)

How can I force the hyperlink to change the first page? That is, xxx.com/PageWithMap.html should navigate to xxx.com/photo1.html

I'm finding that xxx.com/photo1.html opens inside the iFrame on xxx.com/PageWithMap.html if I simply click the hyperlink.

Searching on StackOverflow suggests using window.top.location.href or target="_parent" or target="_top" but I can't get it to work. Is there an added complication since the hyperlink is within a Google Map infoWindow?

Let me know if the above description isn't clear – unfortunately I can't share the actual site yet but I may be able to make a mockup if necessary.

Thanks

Best Answer

This problem is quite popular and the article referenced below provides a great explanation as to why you can't (and shouldn't) do cross-site scripting ever. It also shows how to circumvent in a legal and safe way the problem:

http://softwareas.com/cross-domain-communication-with-iframes

Related Question