Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
5
rated 0 times [  9] [ 4]  / answers: 1 / hits: 30728  / 14 Years ago, wed, october 13, 2010, 12:00:00

I've used window.onbeforeunload to display a custom message when a user attempts to leave a site.



Example:



window.onbeforeunload = function(){
if(some_condition){
return Are you sure you want to navigate away from this page?nAll unsaved changes will be lost.;
}
};


+--------------------------------------------------------+
| Are you sure you want to navigate away from this page? |
| All unsaved changes will be lost. |
| |
| [ Yes ] [ Cancel ] |
+--------------------------------------------------------+


However, I'd like to enhance this a bit. If possible, I'd like to use a custom modal form instead of the generic popup.



Is there a way to do this?


More From » jquery

 Answers
5

The unload event will fire when a user tries to navigate away. However, if you use a DIV as a pop-up the browser will navigate away before the user has a chance to read it.



To keep them there you'd have to use a alert/prompt/confirm dialog boxes. (as far as I know)


[#95333] Monday, October 11, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jameson

Total Points: 534
Total Questions: 103
Total Answers: 102

Location: Lithuania
Member since Fri, Sep 4, 2020
4 Years ago
jameson questions
;