How do I eject the Chrome browser when I close the page "Are you sure you want to leave this side?" "_javascript Skills

Source: Internet
Author: User

First, avoid pop-up prompt box

Search on the Internet a lot, the answer is mostly set window.onbeforeunload=null, but after the trial is invalid.

After two days of this question returned to think again, finally found the answer, here and share with you:

Remove jquery from the page eject (1) first unbind the set popup content to null.

Copy Code code as follows:

$ (function () {
$ (window). Unbind (' Beforeunload ');
Window.onbeforeunload = null;
})

Ii. other relevant [abstract]

(1)window onunload and onbeforeunload events

Here is the implementation in JS, rather than <body onunload= "close ()" > This method!
Because this is unload drop body when the trigger, and no matter any browser, will be closed when the unload off the body!

Model 1:

Copy Code code as follows:

function Close () {
Alert ("This is a Test");
}
Window.onbeforeunload=close;

Model 2:

Copy Code code as follows:

function Close () {
if (document.body.clientwidth-event.clientx< 170&&event.clienty< 0| | Event.altkey)
{
Alert ("This is a Test");
}
}
Window.onbeforeunload=close;

Copy Code
About Model 1:
1. Refresh, multiple windows and Single Window fit.
2. Single Window IE closes the entire IE trigger.
3). IE7 to close a single page trigger in multiple windows
4 other multiple Windows refresh triggers. Turn off the individual and close the whole without triggering

For Model 2:
1. IE Single window and IE7 multiple windows, to close the entire browser before triggering
2. Other multi-window browser refreshes. Close a single page, close the whole without triggering

(2) Create a departure cue box

Binding Beforeunload Events

Copy Code code as follows:

$ (window). bind (' Beforeunload ', function () {
Return ' You have entered the content has not been saved, OK to leave this page? ';
});

Unbind

Copy Code code as follows:

$ (window). Unbind (' Beforeunload ');
Window.onbeforeunload = null;

The above is the full content of this article, I hope you can enjoy.

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.