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

后端 未结 7 1342
鱼传尺愫
鱼传尺愫 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:20

    I managed to solve this problem inside the onbeforeunload event by checking event.target. This way you dont have to use outer variables or any extra bindings.

    window.onbeforeunload = function (event) {
    
        var activeElement = $(event.target.activeElement);
        // console.log('onbeforeunload', activeElement);
    
        var isMailto = activeElement && activeElement.is('[href^=mailto:]');
        var isTel = activeElement && activeElement.is('[href^=tel:]');
    
        if(!isMailto && !isTel) {
            // logic when link is "normal"
        }
    };
    

提交回复
热议问题