Is it possible to make google maps open in a new window when you click on the map image?

They have: 7 posts

Joined: Jan 2009

Hi there,

Does anyone know if it's possible to make an embedded google map open its link in a new window when you click on the map image?

A client wants us to use it, but they want the map to open in a new window rather than navigating users away from their site. I've tried to explain that obviously we are pulling in an external file into the website and therefore have very little control over it, but they are insisting we look still. Any help will be greatly appreciated. The code is below.

<iframe class="iframeBorder" width="505" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.co.uk/maps?f=q&amp;hl=en&amp;geocode=&amp;q=W1F+7TA&amp;ie=UTF8&amp;ll=51.520654,-0.135956&amp;spn=0.006223,0.019484&amp;z=14&amp;iwloc=addr&amp;output=embed&amp;s=AARTsJowriHHOt7le7PzJka7tTgSleZODQ"></iframe>

Thanks very much.

decibel.places's picture

He has: 1,494 posts

Joined: Jun 2008

As you noted, you have little control over the Google maps doc in the iframe.

Pop the map open in a new window and retain the original doc in the opener window.

You need to hardcode the map link url into the opener.

UPDATED CODE!

<html>
<head>
  <title> new document </title>
  <meta name="keywords" content="">
  <meta name="description" content="">
  <script language="javascript">
  <!--
var gmap = false;
onunload = function() {
if (gmap)
{
location = self.location.href;
window.open("http://maps.google.co.uk/maps?f=q&hl=en&geocode=&q=W1F+7TA&ie=UTF8&s=AARTsJowriHHOt7le7PzJka7tTgSleZODQ&view=map","googwin");
}
}
  //-->
  </script>
</head>

<body>
  <iframe onmouseover="gmap=true" onmouseout="gmap=false" class="iframeBorder" width="505" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.co.uk/maps?f=q&amp;hl=en&amp;geocode=&amp;q=W1F+7TA&amp;ie=UTF8&amp;ll=51.520654,-0.135956&amp;spn=0.006223,0.019484&amp;z=14&amp;iwloc=addr&amp;output=embed&amp;s=AARTsJowriHHOt7le7PzJka7tTgSleZODQ"></iframe>
</body>
</html>

you could perhaps open a modal window or lightbox - but that is another technique

They have: 7 posts

Joined: Jan 2009

Hi thanks for the reply, i've had a look at your example and it seems to work ok, however there is a slight flaw in that it seems to open endless amounts of windows - so much so that i had to quit my browser as i couldnt keep up with the closing of them lol.

Unfortunately i'm not great at Javascript so would appreciate your advice.
I had thought of the lightbox method, however the client ruled that out as they didnt like it!

decibel.places's picture

He has: 1,494 posts

Joined: Jun 2008

Excellent point! Sticking out tongue

I have updated the code above to activate if the mouse is over the iframe...

seems to work in IE, Ffox, Opera

They have: 1 posts

Joined: May 2009

Amazingly this works for me in IE6 and IE7. The behavior is strange in Firefox. When I click on the link on the map in the iframe, a new window is opened. However the parent page also goes to google. Any ideas how to keep the parent page from going to google too?

decibel.places's picture

He has: 1,494 posts

Joined: Jun 2008

The issue in Firefox seems to be how FF handles new windows - if you hold down the CTL key when you click, the new window/tab opens as in IE and the original window is preserved.

I have not found a fix for that yet. I do not think it is possible to simulate the CTL key press and I have tried setting the new window target to "_blank" but no luck.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.