Firefox 4 onBeforeUnload custom message

前端 未结 4 2258
眼角桃花
眼角桃花 2020-11-27 17:21

In Firefox 3, I was able to write a custom confirmation popup with:

window.onbeforeunload = function() {
   if (someCondition) {
      retur         


        
4条回答
  •  不知归路
    2020-11-27 17:55

    Addition to the above Answer, I have improved the workaround.

    I have used jquery here. you can use default javascript funciton as well.

    $(window).bind('beforeunload', function() {
        if(/Firefox[\/\s](\d+)/.test(navigator.userAgent) && new Number(RegExp.$1) >= 4) {
            if(confirm("Are you Sure do you want to leave?")) {
                history.go();
            } else {
                window.setTimeout(function() {
                    window.stop();
                }, 1);
            }
        } else {
            return "Are you Sure do you want to leave?";
        }
    });
    

    Tested and working in firefox 11 as well. :)

提交回复
热议问题