Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JavaScript Handling the Unload Event</title> </head> <body onunload="alert('Are you sure you want to leave this page?');"> <h1>This is a heading</h1> <p>This is paragraph of text.</p> <p><strong>Note:</strong> This example may not work. The unload event is not supported properly in most of the browsers.</p> </body> </html>