开发者

how can i catch the browser has gone to exit now

how can I catch that the browser has gone to exi开发者_开发技巧t now using javascript.


If you are looking for catching the window close event try something like this:

jQuery(window).bind('beforeunload', function() {
    return confirm("Do you really want to do that?");
});

found here: How to capture the browser window close event?


If the browser has gone to exit (exited) there is no javascript running anymore, so the answer would be no.

But I'm guessing you are looking for the window.onbeforeunload event.


It only works with back, reload and tab close, not with complete browser close.

<html>
<body onunload="alert('Thank you for visiting');">

<body>
</html>


For JQuery: (source: http://api.jquery.com/unload/)

$(window).unload(function() {
  alert('Handler for .unload() called.');
});

And if you want native Javascript, this works on my Firefox3.6 and Chrome. I do not have any other browsers to test it on right now, but after some google-ing, it looks like it could work on IE too, but Opera might have some issues(?). You should test it for browser compatibility first.

window.onunload = function () {
    alert('unloading');
};
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜