Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
40
rated 0 times [  41] [ 1]  / answers: 1 / hits: 36301  / 15 Years ago, mon, january 4, 2010, 12:00:00

I want to alert a user while the user tries to close the browser with out siginingoff or without saving some settings.



I am ding unload option in another page to alert unload data, but how can i alert a user on window.close(its not taking)



window.onbeforeunload = confirmExit;
function confirmExit(){
if(readCookie(onlineVD) == playing && Confirm_Delete==0)
{
return You are leaving a video which is in play mode.Are you sure want to exit this page?;
}
else{
Confirm_Delete=0;
}
}


I want window.close for on tab close and on window close in all browsers.



Please find me a solution


More From » javascript

 Answers
4

The event code you have already seems to work when I test it. You just need to return false to stop the browser from closing. The user will be asked if they're sure they want to navigate away from the page.



I'm using this shortened version of your code:



window.onbeforeunload = confirmExit;
function confirmExit(){
alert(confirm exit is being called);
return false;
}

[#97932] Wednesday, December 30, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
analiseb

Total Points: 252
Total Questions: 96
Total Answers: 106

Location: Singapore
Member since Sat, Jul 25, 2020
4 Years ago
analiseb questions
;