Avatar of Jagadeesh M
Jagadeesh M
Flag for United States of America asked on

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()

Open in new window

JavaScript

Avatar of undefined
Last Comment
b0lsc0tt

8/22/2022 - Mon
b0lsc0tt

jagadeesh_motamarri,

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......
ASKER CERTIFIED SOLUTION
b0lsc0tt

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Your help has saved me hundreds of hours of internet surfing.
fblack61