 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Execute a script when the document is about to be unloaded in HTML?
The onbeforeunload event attribute’ fires when the document is ready to be unloaded.
Example
You can try to run the following code to implement the onbeforeunload attribute −
<!DOCTYPE html> <html>    <body onbeforeunload = "return display()">       <p>Close this window or press F5.</p>       <script>          function display() {             return "Wanna stay here or leave?";          }       </script>    </body> </html>Advertisements
 