开发者

window.onbeforeunload for a hash URL?

Typically if you have some text and you want to warn the user about saving before leaving the page, you just do something like ....

window.onbeforeunload = function (){
    return "Hey, get back here";
};

Okay, that's fine, except... I have one of those crazy URLs that look like this:

http://example.com/#/Woo/Ajax/headaches/

Of course, the unload event doesn't trigger when jumping between hash tags, so the onbeforeunload doesn't tigger either.

What can I do 开发者_JS百科to alert a user from losing everything because they mis-clicked somewhere?

I'm using http://www.asual.com/jquery/address/ for my hash-management.


I assume you have a system to handle hash changes.. if so then you have to organize the hash sections of your site and add custom behaviour based on if the user goes to "invalid" hash sections.

If you don't have a system, I recommend ben alman's jquery BBQ script.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜