在我的网站上,我有一个文本和按钮,我想接收一封电子邮件,其正文是文本盒中写的文本。一个按钮将在单击时调用函数,该函数将发送电子邮件。在研究此之后,我发现各个论坛上的人们都建议使用mailto:
标签。但是,当我使用以下代码中的mailto
标签时,我不会收到任何电子邮件。我的相关代码如下;
html:
<textarea id="text"></textarea>
<button onclick="myFunction()">Click ME!</button>
javaScript:
function myFunction () {
var x = document.getElementById("text").value;
document.getElementById("p").innerHTML = x;
'mailto:' + 'someone@gmail.com' + '?subject=' + Requests + '&body=' + x;
}
您没有重置文档的href href。您只需计算该值是什么。您需要将location.href
设置为'mailto:' + 'someone@gmail.com' + '?subject=' + Requests + '&body=' + x;
function myFunction () {
var x = document.getElementById("text").value;
var url = 'mailto:' + 'someone@gmail.com' + '?subject=' + "Requests" + '&body=' + x;
window.open(url);
document.getElementById("p").href = url;
}
<textarea id="text"></textarea>
<button onclick="myFunction()">Click ME!</button>
<a id="p">newlink</a>
在这里如何做到这一点:
window.location.href =" mailto:mail@example.org?objects =" somevar '&amp; body =' someothervar;