2010-06-04 55 views
1

在地圖上顯示InfoWindow之前,我正在調用setContent。正在設置的內容包含超鏈接。一切正常,InfoWindows顯示,但是當你點擊「Driving Directions」超鏈接時,什麼都不會發生。帶有超鏈接的Google Maps v3 InfoWindow不起作用

var infoWindowHtml = '<a href="http://www.google.com/maps?daddr=Aliso+Viejo,+CA" target="_blank">Driving Directions</a>' 
infoWindow.setContent(infoWindowHtml); 
infoWindow.open(map, this); 

回答

1

你可以在別的地方有一些問題,或者有被阻斷的新窗口中主動的彈出窗口攔截器,因爲下面簡單的例子完全在我的瀏覽器(Chrome和Firefox):

<!DOCTYPE html> 
<html> 
<head> 
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/> 
    <title>Google Maps API InfoWindow Demo</title> 
    <script src="http://maps.google.com/maps/api/js?sensor=false" 
      type="text/javascript"></script> 
</head> 
<body> 
    <div id="map" style="width: 400px; height: 500px;"></div> 

    <script type="text/javascript"> 
    var map = new google.maps.Map(document.getElementById('map'), { 
     zoom: 4, 
     center: new google.maps.LatLng(-25.36388, 131.04492), 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
    }); 

    var infowindow = new google.maps.InfoWindow(); 

    infowindow.setContent('<a href="http://www.google.com/maps?'+ 
     'daddr=Aliso+Viejo,+CA" target="_blank">Driving Directions</a>'); 

    var marker = new google.maps.Marker({ 
     position: map.getCenter(), 
     map: map 
    }); 

    google.maps.event.addListener(marker, 'click', function() { 
     infowindow.open(map,marker); 
    }); 

    </script> 
</body> 
</html> 
+0

丹尼爾感謝質量的例子。我在所有的瀏覽器中都試過了,它的工作很完美,所以我不認爲這是一個彈出式窗口攔截器。這一定是我正在做的其他事情是在地圖上。我正在收聽InfoWindow的「closeclick」事件。我認爲這可能是劫持超鏈接的點擊,但我評論說,同樣的問題。 以下是有問題的頁面:http://coav.beta2.nssg.com/map/ 深表感謝。 – jacksonakj 2010-06-04 14:57:16

相關問題