Detect InfoWindow Being Closed – Google Maps V3 API

November 2nd, 2010 - Posted by Steve Marks to Javascript / jQuery, Web Development.

Detect Google Maps infowindow Being Closed

If you’re including a map on your website using the Google Maps V3 API there’s a high chance you’ll be including overlaid markers and infowindows that are related to these markers. Adding the markers is simple enough, as is getting the infowindows to open upon clicking them, but what if we need to detect when an infowindow is closed?

I came across this scenario earlier today where I need to set the map back to a certain lat/lon position upon the infowindow being closed. After a bit of research and playing around I figured it out to be something like so:

google.maps.event.addListener(infowindow, 'closeclick', function() {
	alert("I'm Closed");

Simply add the above to within the map initialisation function and you’ll now be able to perform actions upon infowindows being closed.

Note: You’ll need to change ‘infowindow’ in the above snippet to the variable name assigned to the infowindows in your own code.

This entry was posted on Tuesday, November 2nd, 2010 at 8:22 pm by +Steve Marks and is filed under Javascript / jQuery, Web Development. You can follow any responses to this entry through the RSS 2.0 feed.

Fear not, we won't publish this

Comments (3)
  1. Anonymous says:

    thank u sir, it is just what i needed

  2. Javier says:

    That’s exactly what I was looking for. Thanks!

  3. Loughlin says:

    Sweeeet! I was just playing around with this, nice tip ;)