Js window close prompt information (compatible with IE and firefox), jsfirefox

Source: Internet
Author: User

Js window close prompt information (compatible with IE and firefox), jsfirefox

In many cases, when browsing a webpage, we need to consider closing the window when users are not careful, especially when important data is not saved, it is necessary for our program to remind users. In this case, we can use javascript window. onbeforeunload () to prevent users from closing the window. See the following example:

<Script type = "text/javascript"> window. onbeforeunload = function (event) {return 'hello' ;}</script>

In this way, when you press the close button, the following window will pop up (compatible with IE and firefox ):

"Hello" is the return value. When you press Cancel, the page will not be closed. Only after you press OK. The return value is indispensable, even if it is null, otherwise the page will be closed without any prompts. In fact, as long as the window is called. close () will execute the onbeforeunload () function, so we can know that the window will be executed by pressing the close button. close () function, while window. in close (), window is also called. onbeforeunload () function.

With this tips, you no longer have to worry about the losses caused by accidental window close. I hope you will like this 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.