Determine whether the page is closed or refreshed js Code _ basic knowledge

Source: Internet
Author: User
The js code labels that determine whether the page is closed or refreshed are only the onload, onunload, and onbeforeunload events, but not the onclose event. The onunload Event is executed no matter whether the page is closed or refreshed. How can I capture and close the page?

Only onload is executed when the page is loaded.

When the page is closed, only onunload is executed.

When the page is refreshed, execute onbeforeunload first, then onunload, and finally onload. In this way, we can add a tag in onbeforeunload to judge the tag in onunload to determine whether the page is actually closed.



Determine whether the page is closed or refreshed



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.