How does one enable chrome to pop up "are you sure you want to leave this area?" When closing the page ?", Chrome close page

Source: Internet
Author: User
Tags close page

How does one enable chrome to pop up "are you sure you want to leave this area?" When closing the page ?", Chrome close page

I. Avoid a prompt box

I searched a lot on the Internet. Most of the answers are window. onbeforeunload = null, but it is invalid after trial.

After two days, I returned and thought again, and finally found the answer. I would like to share with you the following:

Remove jquery from the pop-up page. (1) unbind it first. Set the pop-up content to null.

Copy codeThe Code is as follows:
$ (Function (){
$ (Window). unbind ('beforeunload ');
Window. onbeforeunload = null;
})

Ii. Other related [Abstract]

(1)Window onunload and onbeforeunload events

This method is implemented in js instead of <body onunload = "close ()">!
This is triggered when the body is unloaded, and no matter what browser, it will unload the body when it is closed!

Model 1:

Copy codeThe Code is as follows:
Function close (){
Alert ("this is a test ");
}
Window. onbeforeunload = close;

Model 2:

Copy codeThe Code is 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 windows are suitable.
2). Close the entire ie trigger in a Single Window.
3). ie7 multiple window close single page trigger
4) Other Multi-Window refresh triggers. Closing a single window or closing a window is not triggered.

For Model 2:
1). For ie single window and multiple ie7 windows, the entire browser must be closed to trigger
2). Refresh other multi-window browsers. Close the single page and close the whole page.

(2)Create exit prompt box

Bind a beforeunload event

Copy codeThe Code is as follows:
$ (Window). bind ('beforeunload', function (){
Return 'the content you entered has not been saved. Are you sure you want to exit this page? ';
});

Unbind

Copy codeThe Code is as follows:
$ (Window). unbind ('beforeunload ');
Window. onbeforeunload = null;

The above is all the content described in this article. I hope you will like it.

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.