So, here I want just to alert true, when window is closed ( I mean particullary tab in browser).
$(document).ready(function(){
});
$(window).unload(function(){
alert('true'); });
tried $(window)
also inside $(document).ready()
, nothing.
You're very limited in what you can do in the context of window.unload
. The browsers won't let you do anything to force the user to stay on the page, and that includes calling alert
.
The best thing you're allowed to do is return a string from an onbeforeunload
handler - the browser will display that to the user, along with a question like "Are you sure you want to leave this page?"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.