野生动物园博览会:"This website has been blocked from automatically composing an email."

Safari mailto: "This website has been blocked from automatically composing an email."

当使用 Safari (iOS 10.2) 并单击 mailto link 时,将显示确认提示和以下消息:

"This website has been blocked from automatically composing an email." Ignore / Allow

我想在我自己的网站上摆脱它,但不知道该怎么做。它可以用 Safari 重现,例如在任何 BBC 文章上单击邮件图标。

Screenshot of dialogue on iPad

我的网络研究让我找到了这些 link:

https://discussions.apple.com/thread/7763735

WillieFromColo Jan 11, 2017 8:25 AM in response to Russ G

Issues with Safari and "This website has been blocked from automatically composing an email."

My research on Google suggests that this Error-type Message started happening in about November with an update to Safari, which likely occurred concurrently with Apple's update to iOS 10.2. As of today (1/11/17) that is the latest version of iOS for iPads and perhaps iPhones, too.

[...]

https://developer.apple.com/safari/technology-preview/release-notes/#r15

Release 15 URL Handling

Navigations to tel: and mailto: links now require a user gesture; navigations without a user gesture will show a confirmation prompt

所以它看起来像一个 Safari "feature"。有谁知道如何防止这个提示?

我最初没有提到的是我们从页面的 JavaScript 部分调用了 mailto。我们现在再次尝试通过更改为基于 HTML 标签的 mailto(带有收件人和主题)来解决该问题,现在它可以在没有对话的情况下以某种方式工作。 所以我认为这个问题自己解决了,但我愿意接受任何解释原因的提示。因此,到目前为止,我还没有将此答案标记为解决方案。

各种第三方 JavaScript 库将拦截对 a 标签的点击,以防止在向服务器发送数据时短暂导航。通常,他们通过 window.location.replace.

以编程方式触发导航

当 mailto/tel 链接以这种方式触发时,Safari 中的更改会弹出警告。

交互,但通常会因 preventDefault 而停止,Safari 不在乎。

如果您使用的库导致此问题,请联系创建者,看看他们是否可以更新它以跳过 mailto/tel 链接上的 preventDefault

发生在用户身上,因为我们使用 window.open(...) 在新的 window 中打开 link。

替换为 window.location.href = ... 仅适用于 Safari :facepalm:.

我们遇到了类似的问题 - 并确定该问题是由 Google 跟踪代码管理器触发的。

具体来说,我们在所有包含 mailto: 前缀的 href 元素上触发事件(在跟踪代码管理器中)。 我们将事件更改为通过单击锚标记内的嵌套 <span> 元素来触发。

这允许在跟踪代码管理器中跟踪事件并删除违规用户提示。 例如。

<a href="mailto:person@example.com"><span>link text</span></a>

我们在使用 Google 跟踪代码管理器 跟踪 mailto-Links 时遇到了这个问题。

我找到了不修改 dom 的解决方案。

我们已激活触发器类型 "Click - Just Links",选项为“等待标签”,“最长等待时间” " 的 2000 毫秒。

禁用此选项后,该消息不再出现。 另一种解决方案是使用 "Click - All Elements"(这总是有效)。

None 这里的解决方案有效。有一个 plugin/script 将自身附加到导致此行为的单击事件。我终于用 jquery 创建了 mailto: link 和 jQuery.

以这种方式在 html 中添加电子邮件

<span class="email-link">email@email.com</span>

并添加此 jquery 以将 <span> 转换为 link

$(function() {
  $( ".email-link" ).each(function( index ) {
    var a = $('<a />');
    var link = $( this ).text();
    a.attr('href', 'mailto:' + link );
    a.text(link);
    $( this ).html(a);
  });
});        

这样您就可以避免任何外部脚本附加到 mailto link 点击事件。