The code below opens a popup-window whenever a marker on the map is clicked. It works:
<script type="text/javascript">
function popup() {
newwindow = window.open('test.php','Test','width=800,height=500');
newwindow.focus();
return false;
}
function addMarker(lat, lng, map){
var latlng = new google.maps.LatLng(lat,lng);
var marker = new google.maps.Marker({
position: latlng,
map: map
});
google.maps.event.addListener(marker, 'click', function() {
popup();
});
}
function initialize() {
var myOptions = {
center: new google.maps.LatLng(47.367633, 8.542557),
zoom: 5,
scrollwheel: true,
mapTypeId: google.maps.MapTypeId.HYBRID,
mapTypeControlOptions:{
style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
},
navigationControlOptions:{
style: google.maps.NavigationControlStyle.SMALL
}
};
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var jsonData = <?php echo $json; ?>;
for(var i = 0; i < jsonData.length; i += 1){
addMarker(jsonData[i].lat, jsonData[i].lng, map);
}
}
</script>
If I add a marker icon, however, the popup-window still opens, but it immediately disappears in the background, i.e., behind the browser window that contains the map:
function addMarker(lat, lng, map){
var latlng = new google.maps.LatLng(lat,lng);
var marker = new google.maps.Marker({
position: latlng,
icon: 'myicon.png',
map: map
});
google.maps.event.addListener(marker, 'click', function() {
popup();
});
}
What is the reason for this behavior?