5

I have a VisualForce page that I'd like to do some cleanup if the user navigates off the page without performing certain actions. Notably, if they don't submit the form with either a submit button or cancel. Most often using the back button on the browser. I can't use remoting(AJAX) because the page most often runs in a console and iFrames do not allow AJAX execution.

Any ideas on how to emulate the clicking of the "Cancel" button?

5

I actually ran into a similar issue a while back and blogged about it.

http://michaelwelburn.com/2013/04/08/confirming-a-user-really-wants-to-leave-a-visualforce-page/

The gist of it is that you can keep a JavaScript variable to determine whether you want to notify the user that he is leaving (default it to true). Upon submit set that variable to false. Then, as the page is submitting (and subsequently "unloading"), your onbeforeunload event is called and you can check that boolean value prior to prompting the user with the popup. This gives you a little more control as to when to dynamically show it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.