Wonderful のbeforeunload

Source: Internet
Author: User

(As always appears)

Write the front

The pit to the Beforeunload or a blog post?

---------------------------------------------------

A general event returns a value to it that is used to block some of the default behavior of the browser or to prevent the next action by itself.

But this beforeunload is a wonderful thing. Its return value to help Ning karma is different!

When you turn off the brush line back redirect, the browser will play a window where the text description is the value of the return value

For example, now to implement the refresh after jumping out of the message window and then triggered an action will not pop up the message window directly jump

As follows

<href= "javascript:;" ID = "a" >btn</a>
var k;     function () {        ifreturn;         return 6666;    }     function () {        function(e) {            k=1;             = ' http://www.baidu.com ';        }    }

After the window is refreshed, the message is 6,666 o ' btn after the direct jump link has no problem (almost all browsers)

The Click event is then modified as follows

function (e) {        setTImeout (function() {            k=1;             = ' http://www.baidu.com ';        },2333)            }

Click the button after 2 seconds after the jump is this right ... But IE 8 9 10 is all directly pop-up message 6666! in 2 seconds after the jump!

Where is the problem?

href= "javascript:;"

In this case, IE 7 8 9 10 is useless. That is, the default jump for href is not canceled.

So the order of execution is click->unload->settimeout->unload->.

Knowing the problem is a good solution.

For IE plus event.returnvalue = False this solves!

But wait.

Whose pot is this question in the end? The use of Event.returnvalue really solves it, but it's in a place where it doesn't have to be.

Why use a tag for a button that doesn't need any links? It also uses JavaScript with compatibility issues:;? Is it convenient for a gesture mouse?

Too much to spit out. The number of pages that will cause the above problems to be refactored will be countless. Wash and sleep.

Wonderful のbeforeunload

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.