(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