Does anyone know how can add click event into google map info window in javascript? I want to be able to get click event from popup info window. Is this possible or not ?
Asked
Active
Viewed 8,146 times
0
-
1Yes it is possible.Write you google map code where you are rendering the infowindow he i will edit your answer – black_pottery_beauty Aug 05 '16 at 07:19
-
5duplicate question : http://stackoverflow.com/questions/12102598/trigger-event-with-infowindow-or-infobox-on-click-google-map-api-v3 – codeGig Aug 05 '16 at 07:29
1 Answers
7
<!DOCTYPE html>
<html>
<head>
<script
src="http://maps.googleapis.com/maps/api/js">
</script>
<script>
var myCenter=new google.maps.LatLng(51.508742,-0.120850);
function initialize()
{
var mapProp = {
center:myCenter,
zoom:5,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
var map=new google.maps.Map(document.getElementById("googleMap"),mapProp);
var marker=new google.maps.Marker({
position:myCenter,
});
marker.setMap(map);
var infowindow = new google.maps.InfoWindow({
content:"<button onclick='xyz()'>abcd</button>"
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map,marker);
});
}
google.maps.event.addDomListener(window, 'load', initialize);
function xyz(){
alert('Hello')
}
</script>
</head>
<body>
<div id="googleMap" style="width:500px;height:380px;"></div>
</body>
</html>
Please check this will work for you

black_pottery_beauty
- 861
- 8
- 17
-
Thanks, as I understand we only can add the button on the popup window and get button click event, other solutions are not.? – Developer Aug 05 '16 at 07:35
-
@Developer It doesn't need to be a button. You can use any element you want. You just give it onclick handler like in the example. – karlo1zg Oct 29 '19 at 12:52