1

I have this code in javascript below:

function ExitPage(){return 'Wait!';}


<body onbeforeunload="return ExitPage();">

I would like to run some codes when the user clicks on the "cancel" button. How will I accomplish this?

Any suggestion would be greatly appreciated.

Thanks

3
  • I see no buttons. belly or otherwise Commented May 9, 2011 at 16:15
  • Do you want to have an alert pop up that says 'Wait!'? Commented May 9, 2011 at 16:17
  • When the page is closed, there will be a confirm box that will appear having an OK and Cancel button. When the user clicks on the OK button, it will continue to close the page. But when the user clicks on the Cancel button, I would like to run some codes. Commented May 9, 2011 at 16:18

1 Answer 1

2

This is not possible. At least not in a safe way - the only think you could do is starting a timer in the onbeforeunload handler that runs for e.g. 10 seconds. If the page is still open after this time this timer then runs your code.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.