Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
124
rated 0 times [  125] [ 1]  / answers: 1 / hits: 38057  / 11 Years ago, wed, march 20, 2013, 12:00:00

I've try this:



<body onunload=LogoutNoAsk();> </body>


and the function is:



function LogoutNoAsk()
{
alert(Please press the Logout button to logout.);
parent.close();

}


When I press close which is the 'X' button on the top right of the window, it close straightaway without the warning message. What's wrong?


More From » javascript

 Answers
17

You're actually wanting to use the onbeforeunload event which allows you to block the close event.



See the MDN reference for details, but the code required would be:



window.onbeforeunload = function(e) {
return 'Please press the Logout button to logout.';
};

[#79479] Monday, March 18, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
micayla

Total Points: 148
Total Questions: 92
Total Answers: 109

Location: Aruba
Member since Sat, Oct 2, 2021
3 Years ago
;