Prompt when Jquery closes the page

Source: Internet
Author: User

When we leave the page, the prompts are displayed on the page where we send news or write logs. If we leave the page when we do not save the information in the Baidu space or QQ space, the following describes how to use beforeunload of jquery to implement this method.

Prompt code displayed when jquery leaves the page

The Code is as follows: Copy code

// Bind the beforeunload event
$ (Window). bind ('beforeunload', function (){
Return 'the content you entered has not been saved. Are you sure you want to exit this page? ';
});

// Unbind, which is generally placed in the submitted trigger event
$ (Window). unbind ('beforeunload ');

Js exit page prompt

The Code is as follows: Copy code


Window. onbeforeunload = function (event ){
Return confirm ("are you sure you want to exit ");
}


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.