This example uses the onbeforeunload event to ask users whether they want to remain on the current page or navigate to a new URL.
When the user clicks on the hyperlink or attempts to close the browser window, the onbeforeunload event fires on the body and a dialog box appears. If the user clicks OK in the dialog box, the page either navigates to the new URL or the window closes; otherwise, the page remains the same.
Click here to navigate to www.microsoft.com.[Right-click and choose View Source from the shortcut menu.]
© 2007 Microsoft Corporation. All rights reserved. Terms of use.