Capture control for browser shutdown events (such as: Top right corner x, taskbar right button off, tab Check Point x, etc.)

Source: Internet
Author: User

Today, I have a shutdown event to listen to the capture browser , because I want to do something before I close it, considering that there are many ways to close the browser, such as: the top right corner x, the taskbar right close, the tab Check Point x , and so on. But at the moment I just need to put the top right corner x, tab Check point x operation to capture the control on the line.

For I have always liked to do background development, the front desk just slightly understand a little bit. Originally just do a page transformation, and later found that there is work to do, I had to bite the bullet dry, who called us a developer.

After a data query and testing, suddenly in front of the bright and cheerful, the problem solved. For IE browser through the onbeforeunload event can be a good capture control for Firefox FF browser through the onunload event capture control.

Now the code to share, hope that there is such a need for help, you can refer to.

//For IE browser through the onbeforeunload event can be a good capture control Window.onbeforeunload = function () {if (document.all) {var n = Window.event.screenx-window.screenleft; var b = n > document.documentelement.scrollwidth-20; if (b | | Window.event.clientY < 0 | | window.event.altKey) {//function invokes the method you want to process}}}//For Firefox Browser Control window via OnUnload event capture. OnUnload = function () {if (!document.all) {if (document.documentelement.scrollwidth==0) {//function invokes the method you want to process}}}

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.