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

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

    Add a flag and see if it is flipped, set the flag on the link click.

    var ignore = false
    window.onbeforeunload = function() {
        if (changed && !ignore) {
            return "You have unsaved changes.  Do you really want to leave this page without saving?";
        } else {
            ignore = false;
        }
    }
    

    And the link

    <a class="button button-alt" href="mailto:foo@foo.com" onclick="ignore=true">Report a problem</a>
    

    It would be better to add the onclick with JavaScript code.

    0 讨论(0)
提交回复
热议问题