4

I'm looking for a way to make a Google Map marker a simple link (<a href="">).

I don't want to reproduce a link behavior with Javascript (location.href for example) because I want the user to be able to open the link in a new Tab or Window (using the middle click for example).

Is there a way to do that?

Matthieu Napoli
  • 45,472
  • 43
  • 162
  • 249

3 Answers3

1

There is a workaround for this problem.

  1. Wrap the google map div with a link with href="#"
  2. Set mouseouver and mouseout events of the markers to update the link href (mouseover sets the link to the page corresponding to the marker, mouseout sets it back to "#").

This way, middle click / ctrl click / normal left mouse button click all have the desired classic behaviors, and the overhead is very limited.

This solution works for a fullscreen map, because following the "#" href will not have any effect. If you want this solution to work on a page that is more than -one screen height- high, you should also add an click event listener on the link to block the event propagation when the href is set to "#".

Community
  • 1
  • 1
Renan Le Caro
  • 362
  • 1
  • 7
0

Interesting idea. Only solution that comes to my mind would be to use jquery to wrap each marker element into <a href="..." />:

$(something).wrap('<a href="..." />');

The problem is how to find all markers, i.e. what would be that expression "something".

Tomas
  • 54,903
  • 47
  • 225
  • 361
0

Because a click on a marker is a javascript event you can only use location.href/window.open functions.

If you want standard html links then your best option is to open a infowindow when the user clicks on a marker and have the content of infowindow be a html link.

skarE
  • 5,860
  • 2
  • 21
  • 23