Closethepageandseewhathappens!

&n"/>

Closethepageandseewhathappens!

&n">

Home  >  Article  >  Web Front-end  >  In JavaScript, what is the purpose of the "onunload" event?

In JavaScript, what is the purpose of the "onunload" event?

WBOY
WBOYforward
2023-09-16 18:25:02948browse

In JavaScript, what is the purpose of the onunload event?

The unload event is triggered when the page is unloaded (or refreshed). You can try running the following code to learn how to implement the onunload event in JavaScript.

Example

<!DOCTYPE html>
<html>
   <body onunload="newFunc()">
      <p>Close the page and see what happens!</p>
      <p>This event may give unexpected results.</p>
      <script>
         function newFunc() {
            alert("Thank you!");
         }
      </script>
   </body>
</html>

The above is the detailed content of In JavaScript, what is the purpose of the "onunload" event?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete