开发者

How to make a warning window just like stackoverflow when close the edit window?

I found it very useful.But how can t开发者_JAVA百科hey get it?

thank you very much!!


You could use the window.onbeforeunload event:

window.onbeforeunload = function (e) {
    var e = e || window.event;

    // For IE and Firefox
    if (e) {
        e.returnValue = 'Are you sure you want to leave this page';
    }

    // For Safari
    return 'Are you sure you want to leave this page';
};

Obviously you shouldn't attach this event systematically because it is very annoying from a user standpoint. You should attach it only in case for example that the user has some unsaved work in order to warn him as StackOverflow does.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜