开发者

window unload method in javascript

Why doesn't this code work?

$(window).unload(function(){
    window.location = 'http://www.google.com/'开发者_如何学C;
});


Firefox and Chrome do not allow a location change after the unload or beforeunload events have fired.

So your code might work in IE and Opera, but will (what I assume to be good behavior) fail in the other two Browser that I've named.


href is not present in you redirection

 window.location.href = 'http://www.google.com/';


Note that the unload event is called when the user moves away from the page (for any reason: he can close the browser, click on a link, insert a new url, click 'back'...) and should be used only for messages or confirmations (like 'Are you sure?') or any actions that do not interfere with user choice.

See jQuery documentation for some suggestions.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜