Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
67
rated 0 times [  72] [ 5]  / answers: 1 / hits: 33717  / 11 Years ago, mon, july 22, 2013, 12:00:00

I'm trying to alert something out after closing page.



A simple window.unload example as below :



HTML



<html>
<body>
<script src=http://code.jquery.com/jquery-1.10.1.min.js></script>
<script src=http://code.jquery.com/jquery-migrate-1.2.1.min.js></script>
<script src=test.js type=text/javascript>
</html>


test.js



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


P.S :



I have tried javascript too, but doesn't alert anything out !



test.js



window.onunload = function() {
alert(Bye now!);
};

More From » jquery

 Answers
33

Most browsers prevent alert in unload. The best you can do is to use an onbeforeunload handler that returns a string - the browser will show that string to the user:



window.onbeforeunload = function() {
return Bye now!;
};


Demo here.


[#76822] Sunday, July 21, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
stacie

Total Points: 476
Total Questions: 92
Total Answers: 102

Location: Bosnia and Herzegovina
Member since Tue, Mar 29, 2022
2 Years ago
stacie questions
Fri, Jun 26, 20, 00:00, 4 Years ago
Thu, Jan 23, 20, 00:00, 4 Years ago
Fri, Aug 30, 19, 00:00, 5 Years ago
Fri, Aug 2, 19, 00:00, 5 Years ago
;