Run ❯
Get your
own
website
Result Size:
625 x 565
×
Change Orientation
Save Code
Change Theme, Dark/Light
Go to Spaces
<!DOCTYPE html> <html> <body> <h1>HTML DOM Events</h1> <h2>The beforeunload Event</h2> <p>Use the addEventListener() method to attach a "beforeunload" event to the window object.</p> <p>Close this window, press F5 or click on the link below to invoke the beforeunload event.</p> <a href="https://www.w3schools.com">Click here to go to w3schools.com</a> <script> window.addEventListener("beforeunload", function(event) { event.returnValue = "Write something clever here.."; }); </script> </body> </html>