Capture browser window closing event

xiaoxiao2021-03-06  18

I encountered a difficult problem today: How to capture the browser window to close the event with JavaScript or other scripting languages. The browser refers to this is only IE, and the closed closed is to click the user directly click on the breeze fork in the upper right corner of the browser. Then why should I capture this event? ? What is the use of caught it? ? In fact, in order to handle some special functional operations when closing the browser, for example: When you know that the browser is turned off, the client can send a request to the server, requiring it to end this customer's session. This is the easiest and most useful example. 1. Let me talk about how to take the initiative to close the browser window: IE provides a Window.close () method, call it to actively shut down the browser window, then meet my requirements, I can send the request to the server. 2. Let's talk about the case where the user directly clicks the breeze window in the upper right corner of the browser: IE provides a Window.onunload event, which is used to trigger immediately before the Window object is uninstalled, that is, the browser window is closed. This event is triggered, but it will also trigger the event when reloading or refreshing the page, so this method does not reach the purpose of capturing the browser window to close the event. I have also tried other many other ways, but I have a different situation in the end of 2, and I have not solved the problem. I have desperate, I am now thinking about the way, I have some ideas, I have no way to solve this problem, I am here Thank you.

转载请注明原文地址:https://www.9cbs.com/read-41193.html

New Post(0)