mailto link (in chrome) is triggering [removed] - can i prevent this?

后端 未结 7 1639
鱼传尺愫
鱼传尺愫 2021-02-18 19:09

Possibly related to How to open mailto link in Chrome with Window.open without creating a new tab?

Hi all. I have a form page where i\'ve put a window.onbeforeunload co

7条回答
  •  天命终不由人
    2021-02-18 19:36

    Building off of epascarello's solution, the following JQuery code should do the trick:

        var ignore_onbeforeunload = false;
        $('a[href^=mailto]').on('click',function(){
            ignore_onbeforeunload = true;
        });
    
        window.onbeforeunload = function() {
            if (!ignore_onbeforeunload){
                return "Halt! you are not supposed to leave!";
            }
            ignore_onbeforeunload = false;
        };
    

提交回复
热议问题