call a function before windows.onbeforeunload event triggers
Hi Experts -
The idea is to check if the form is dirty and display a confirm dialog box to the user to save the page before navigating away....i'm done with 99% of this task using Jquery.
here is the last piece...
Now i need call a function ( callThisAtLast() ) after the user clicks on "OK" confirm dialog box and just before the page unloads...how do i achieve this?
Here is the sample snippets that prompts the dialog box.
Thanks
function callThisAtLast(){;;;;;}window.onbeforeunload = confirmExit;function confirmExit(){ if (verifyIfFormChanged== true ){ if ( formIsChanged == true ){ return " !!! You have unsaved data on this page !!!"; }else{ if (checkOthers()) { }else{ return " !!! You have unsaved data on this page !!!"; } } }}// end of confirmExit()
The onbeforeunload event will only fire the confirm. You can't have it run other script after that no matter what the result of the confirm is. You should have the confirm worded so the user knows to choose Cancel and go back to save the info. The script won't be able to do it for them at this point.
Let me know if you have any questions or need more information.
b0lsc0tt
Jagadeesh M
ASKER
hmm...then i would i do this.
Once the onbeforeunload dialog box appears and user clicks on OK button a request is sent to the server to fetch the next page depending on which screen is selected from the menu....now i need to show the user that request is under processing...!!!
currently when the user clicks OK..the request is passed to the server but it appears as if nothing is happening.
I just wanted to show the user a visual cue.. may be an hour glass that the current request after clicking OK is in progress......
The onbeforeunload event will only fire the confirm. You can't have it run other script after that no matter what the result of the confirm is. You should have the confirm worded so the user knows to choose Cancel and go back to save the info. The script won't be able to do it for them at this point.
Let me know if you have any questions or need more information.
b0lsc0tt