Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make Google marker url open in a new browser window or tab?

I have some markers on a Google map and would like to make it open a new tab or window when they are clicked on. I only am able to open the clicked marker url in the same browser window tab.

This is how it works now...

var latlon = new google.maps.LatLng(MAP_FOCUS_LATITUDE, MAP_FOCUS_LONGITUDE);
var myOptions = {
   center : latlon,
   zoom : 14,
   mapTypeId : google.maps.MapTypeId.ROADMAP,
   mapTypeControl : false,
   navigationControlOptions : {
   style : google.maps.NavigationControlStyle.LARGE
   }
};
var map = new google.maps.Map(document.getElementById("mapholder"), myOptions);
var marker = new google.maps.Marker(
{
    position : new google.maps.LatLng(10.0,20.0),
    title : "Blah",
    url : "http://www.myurltest.com"
});

google.maps.event.addListener(marker, 'click', function() { 
    window.location.href = this.url;
});

In HTML, normally you can do this to open a link in a new tab... so how do I get this effect ?

<a href="http://www.myurltest.com" target="_blank">Blah blah</a>

I would appreciate any assistance !

like image 548
bluesky Avatar asked Dec 25 '22 14:12

bluesky


1 Answers

The url property it's to define a sprite sheet for style the icon, nevertheless change the callback of click for this

window.open(this.url, '_blank');
like image 120
Jorge Avatar answered May 02 '23 10:05

Jorge