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?

1 Answer 1


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


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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .