简体   繁体   中英

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 !

url属性是为样式图标定义精灵表,但是为此更改了click的回调

window.open(this.url, '_blank');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM