如何使Mailto在Android chrome上正常工作? [英] How to get mailto working on android chrome?

查看:83
本文介绍了如何使Mailto在Android chrome上正常工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在这里看到了几个有关mailto不能在android上运行的问题,我的问题比这更具体.我的网站有一个mailto链接设置作为提交"按钮,可以将在我的网站上填写的表格直接发送到我的电子邮件中.该链接在chrome和firefox的桌面上正常工作,并且也经过了测试,并且可以在iPhone 8+上运行.但是,该按钮在我的Samsung Note 8上的Chrome浏览器中什么也没做.我以为它只是android,所以我决定在Samsung的本地互联网服务上对其进行测试,并且效果很好!因此,它可以在台式机版的Chrome和Android上的非Chrome网络浏览器上使用...只是Android上的Chrome浏览器有一些特别之处,与我的mailto链接不兼容.

So I've seen a couple questions on here about mailto not working on android, my problem is a little bit more specific than that. My website has a mailto link setup as a submit button to send forms filled out on my website straight to my email. The link works just fine on desktop in chrome and firefox, and was also tested and working on an iPhone 8+. However, the button did absolutely nothing in Chrome on my Samsung Note 8. I thought it was just android, so I decided to test it on Samsung's native internet service, and it worked just fine! So it works on the desktop version of Chrome and on non-chrome web browsers on Android...There's just something specifically about the Chrome browser on Android that isn't getting along with my mailto link.

旁注:我在其他地方读过,在mailto链接中添加"target =" _ top可使它在Android设备上运行.

Side note: I've read elsewhere that adding in "target="_top" to the mailto link gets it working on Android devices. This did not work for me.

我的mailto链接嵌套在我的网页的表单声明中(我怀疑我的"target ="_ top"可能没有帮助吗?),写为:

my mailto link is nested in the form declaration of my web page (I suspect that may have a part in my the "target="_top" didn't help?) and is written as:

<form class="questionnaire" action="mailto:carl@cuttingedgelighting.com?Subject=New%20Vendor" target="_top" method="post" enctype="text/plain">

我不确定还有哪些其他代码会有所帮助,请告诉我,我很乐意发布您可能需要的任何内容.谢谢!

I'm not sure what other pieces of code may be helpful, let me know and I'll gladly post whatever you might need. Thank you!

推荐答案

在from中使用mailto通常是不可靠的,因此主要是与chrome mobile

Using mailto in a from is generally not reliable, so it is mostly a compatibility issue with chrome mobile The Mythical Mailto.

最好,最优雅的解决方案是处理表单请求服务器端,而不是发送电子邮件.

The best and most elegant solution would to handle the form request server side instead of sending an email.

但是,另一种不太优雅的解决方案是在页面上添加隐藏的锚标签,在JS中捕获事件,动态构建mailto href,将链接附加到锚标签href属性,然后使用触发锚标签点击JavaScript.请参阅下面的JS小提琴.在chrome手机上进行了测试.

However, another less elegant solution would be adding a hidden anchor tag to the page, catching the event in JS, building the mailto href dynamically, appending the link to the anchor tag href attribute, and then triggering the anchor tag click using JavaScript. See JS fiddle below. Tested on chrome mobile.

$('.questionnaire').on('submit', function(e) {

  var messageBody = '';
  $.each($('.questionnaire').serializeArray(), function(i, field) {
    messageBody += field.name + ": " + field.value + '%0D%0A';
  });

  var hreflink = "mailto:carl@cuttingedgelighting.com?Subject=New%20Vendor&body=" + messageBody;
  $('.mail').attr("href", hreflink);
  e.preventDefault();
  $('.mail')[0].click()

});

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form class="questionnaire" target="_top" method="post" enctype="text/plain">


  First name:<br>
  <input type="text" name="firstname" value="Foo">
  <br> Last name:<br>
  <input type="text" name="lastname" value="bar">
  <br><br>
  <input type="submit" value="Submit">
</form>

<a class="mail" href="mailto:someone@example.com?Subject=Hello%20again" target="_top" style="display: none;">Send Mail</a>

这篇关于如何使Mailto在Android chrome上正常工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆