How to close InfoWindow

714 views
Skip to first unread message

JB Churchill

unread,
Oct 30, 2009, 3:29:38 PM10/30/09
to Google Maps JavaScript API v3
I've noticed that in some of my older google maps (v2) scripts that if
I click outside of the infowindow, it closes. In some of my newer
scripts based on this example, it doesn't close (the window persists).

I'm trying to figure out a way to get it to close like it used to.
I'm currently using a script based on this example
http://code.google.com/apis/maps/articles/phpsqlajax_v3.html

Here is an example of a script where the window closes when you click
the map outside of the window. This is what I hope to acheive.
http://code.google.com/apis/maps/documentation/examples/map-infowindow.html

Can anyone help me figure out how to set this up ?

Michael Ring

unread,
Oct 30, 2009, 3:34:21 PM10/30/09
to google-map...@googlegroups.com
function initialize() {

currentwindow = null;

google.maps.event.addListener(map, "click", function() {
if (currentwindow) {
currentwindow.close();
}
});

}

You can also include the code in your infowindow click function (less
currentwindow = null;).

This will close the window when you click on the map or trigger another
infowindow.
Reply all
Reply to author
Forward
0 new messages