JavaScript to determine page closure, page refresh implementation code _JAVASCRIPT skills

Source: Internet
Author: User
Tags close page closure

Today, because the project needs to determine the user to leave the page to determine whether the user's behavior is closed or refreshed
Although there is no direct method, but through a certain skill can also do
Have to sigh the power of JavaScript!!
Take a look at the code:

Copy Code code as follows:

Window.onunload = function () {      
& nbsp;       var a_n = window.event.screenx-window.screenleft;       
        var a_b = a_n > document.documentelement.scrollwidth-20;      
         if (a_b && window.event.clienty< 0 | | window.event.altKey) {       
                   Alert (' close page behavior ');
       }else{
                   alert (' Jump or Refresh page behavior ');    
            }
}

In fact, by leaving the page behavior time onunload trigger time to detect the window size of the browser at this time, according to the size of the user is to determine the refresh, jump or shutdown behavior.

Compatible with the major browsers!

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.