Forum Moderators: open

Message Too Old, No Replies

Opening link within iframe with target top

         

greencode

6:33 pm on Oct 15, 2010 (gmt 0)

10+ Year Member Top Contributors Of The Month



Okay, this is not as straight forward as it first seems as it's an actual issue with Google Maps. Basically when you get the code for a Google Map it is then contained within an iframe but just recently (within the past year) instead of links contained within the info window of a map marker opening in the top window it is instead opening in the self window.

So, if you have a link to another website, it will open within the current iframe instead of opening in the entire page.

What I'm wondering is whether there is any way, possibly using javascript, to force any link contained within the iframe (which I can give a name to) to open with target="_top".

There's no way to add this to the link in the Google Map because it instantly strips out this code when it is saved and I'm also not technical enough to attempt the Google Maps API.

Any help or advice would be greatly appreciated.

Thanks

rainborick

7:13 pm on Oct 15, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I don't think you can do this with JavaScript due to browser security issues. I did a quick search and didn't see any obvious solutions. You might try using a script to fetch the page from Google and then inserting a <base target="_top"> tag in the <head> before serving it to the browser.

greencode

7:46 pm on Oct 15, 2010 (gmt 0)

10+ Year Member Top Contributors Of The Month



Thanks for your help with this - really appreciate it.

I attempted to add the code you suggested but that wouldn't work. I had a quick hunt around the web - adding the code you added and found this code, which seems at first look to be working okay. Is there any downside to using such a script?

<meta http-equiv="Window-target" content="_top" />
<base target="_top" />
<script type="text/javascript">
<!--
if (top.frames.length!=0)
top.location=self.document.location;
// -->
</script>

rainborick

8:52 pm on Oct 15, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Sorry, I should have been more specific. I meant use a PHP or Perl script to fetch the page from Google and insert the <base> tag in the <head>. It's simple enough to do. The problem is that Google doesn't like automated accesses to their services, so you have to work around that a bit. It's a good idea to cache the data periodically so you don't have to fetch it on every page view on your site.