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

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

    Some other solution with pure JS and using the focused element:

    window.addEventListener("beforeunload", () => {
      const isMailTo = document.activeElement.protocol === "mailto:";
    
      if (!isMailTo) {
        // do your stuff
      }
    });
    

提交回复
热议问题