How to listen for events when a browser closes a page

clipboard.png

as shown in the figure, how to determine that the user clicked on this X, and execute the corresponding method.

Feb.27,2021

cannot listen. It can be detected by heartbeat.


window.onbeforeunload


window.onbeforeunload = (e) = > {

// doSomething

}

Menu