I noticed some problems with the other answers.
Answer of Marcus Rommel and slawekwin:
When a marker is clicked, the map click event is fired afterwards. So when marker click opens the window, the propagation of the click event to map will close the window again immediately.
Answer of user1724001:
Creating a listener everytime a marker is clicked is also not a good idea. This pollutes the memory.
Therefore i just want to add some additional information to the first answers, to stop event propagation to the map. The Windows will then only be closed, if no marker is clicked.
marker.addListener("click", function(event) {
// open your window here
event.stopPropagation(); // this prevents propagation of marker click to map click
});
map.addListener("click", function() {
// close your window
});