【发布时间】:2012-04-02 04:30:09
【问题描述】:
可能与How to open mailto link in Chrome with Window.open without creating a new tab?有关
大家好。我有一个表单页面,我在其中放置了一个 window.onbeforeunload 确认,以防止人们导航并意外丢失他们的更改:
window.onbeforeunload = function(){
if(changed)
return "You have unsaved changes. Do you really want to leave this page without saving?";
};
其中changed 是一个变量,我在用户进行任何更改时设置为true。没关系。但是,我还向页面添加了一些 mailto 链接,如下所示:
<a class="button button-alt" href="mailto:foo@foo.com">Report a problem</a>
即使 mailto 没有离开页面(它正在打开用户默认的邮件应用程序),它仍然会触发 onbeforeunload 事件,提示确认框,这很烦人。我可以绕过它在链接上设置target="_blank",但随后用户坐在一个空标签中。
我可以将 mailto 链接设置为不触发 onbeforeunload 事件吗?我想到了一种非常骇人听闻的方法,方法是使用另一个临时 javascript 变量,这会导致 onbeforeunload 确认不触发,但它似乎有点脏。无论如何我都会在等待回复时这样做,但有人有更好的解决方案吗?
谢谢,马克斯
【问题讨论】:
标签: javascript mailto onbeforeunload