Google Maps v3 InfoWindow with Hyperlink does not work
Prior to showing an InfoWindow on the map I am calling setContent. The content being set contains a hyperlink. Everything works and the InfoWindows is displayed, however when you click on the "Driving Directions"开发者_运维问答 hyperlink nothing happens.
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);
You might be having some problem elsewhere, or there's an aggressive popup blocker that is blocking the new window, because the following short example works perfectly in my browsers (Chrome and 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>
精彩评论