Processing of browser close events

Source: Internet
Author: User

Usually there are two methods to choose when the browser is closed: 1. onUnload 2. onbeforeunload

Because 1 is executed in different browsers and some are not executed, it is usually handled in the onbeforeunload event.

This event occurs in many situations:

  1. Refresh page
  2. PostBack
  3. Click link
  4. Browser navigation before and after operations

 

Sometimes you do not need to execute Close event in some steps such as clicking a link or refreshing, so we can use some methods to exclude these operations. Of course, we cannot detect the front and back of the navigation, and we cannot eliminate it.

Principle of exclusion:

Set some flag spaces in the operation that you do not want to execute the script to close the script, and then judge in the event. The simple logic is as follows:

$ ("A"). Click (function () {isclose = false ;});

Window. onbeforeunload = function () {If (isclose) {do ()}}

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.