Is there a way to determine if the browser window is closed?

How can I tell if the browser close button is clicked?

+3
source share
8 answers

From the JavaScript Event Reference , the closest match is the OnUnload event. However, this also catches navigation from the page (and therefore, you do not want the functions to run if the user really clicks on the link.)

There is no guarantee that the server will receive a message about closing the browser window. For example, an older method that involved creating a small popup would be blocked by most modern browsers. Using AJAX may work, but the browser window may close before trying to connect.

+5

:

$(window).unload( function () { alert("Bye now!"); } );

?

jQuery.

, Demoli, ( ).

edit: ​​.

+3

, , ,

, ,

+2

onbeforeunload, onunload. IE 7 (, , ) 100% , unload, beforeunload.

, window.onbeforeunload=function(){}

, prototype.js: Event.observe(window, 'beforeunload', function(){});

+1

, , , . IE. IE.

<body onunload="if(self.screenTop>9000){unloadFunction();}">

, , unloadFunction , . , . !;)

+1

, (?) - .

window.closed, . , .

, , "" - .

, , .

0

ajax-, ( ) . (, ), .

0

Northsouthwhat, , onbeforeunload , , , .

0

Source: https://habr.com/ru/post/1699092/


All Articles