SoFunction
Updated on 2025-03-06

Google Map V3 binding bubble window (infowindow) Dom event implementation code

When debugging the functional module, I found that no matter how to use the method, I cannot handle the binding event of the div added in infowindow. Depressed! I searched many methods online but it was useless.
Later I thought about it and checked the official API and found that there was a domready event in the following Events

Official explanation
This event is fired when the containing the InfoWindow's content is attached to the DOM. You may wish to monitor this event if you are building out your info window content dynamically.
My understanding roughly means the callback function after dynamically added Dom elements in InfoWindow is completed.
js is a single-threaded engine. Events can only be bound after the DOM is created. This should be very simple to understand!
Looking at the js code written by my colleague, there are a lot of delays such as setTimeout. I guess I didn’t figure out the smooth execution of the script. I felt that the delay was only a few seconds, but it was actually a big problem. Which scripts need to be executed first and which ones need to be executed later are in sequence.
Events that listen to Dom elements provided by Google Map

On the code

Copy the codeThe code is as follows:

(infowindow,"domready",function(){
var Cancel = ("Cancel");
var Ok=("Ok");
(Cancel,"click",function(){();});
(Ok,"click",function(){();});
});

Official API: /maps/documentation/javascript//reference?hl=zh-cn