繁体   English   中英

当前html页面的“mailto”

[英]“mailto” of the current html page

我正在尝试从当前 html 页面的客户端生成一封电子邮件(更准确地说,我的页面中名为“inc”的 div)。 我被困在我有这个代码的第一步:

    function emailCurrentPage() {
    var htmlData = document.getElementById('inc').innerHTML;
    window.location.href = "mailto:?subject=" + document.title + "&body=" + htmlData;}
    <a href="javascript:emailCurrentPage()">Mail this page!</a>

当我按下链接时,什么也没有发生,调试时我可以在“htmlData”变量中看到 html 代码。

此外,当我将第三行中的“htmlData”更改为“bla bla”或什至<html><body></body></html>之类的文本时,电子邮件正在正常打开。

mailto不能使用 htmlData 的原因是什么?

还有一个小问题。 你认为我发送 HTML 页面的方式正确吗? 因为我怕以后无法将 HTML 代码转换为电子邮件中的 HTML 页面。

使用 href 调用 JS 函数肯定不是很酷。 您还需要格式化您的 mailto: 链接。

 <button onclick="javascript:emailCurrentPage()">Mail this page!</button> <script> function emailCurrentPage() { var htmlData = document.getElementById('inc').innerHTML; window.location.href = 'mailto:?subject="' + document.title + '"&body=' + htmlData;}</script> <main id="inc"> Some text here </main>

我认为 href 一个函数并不酷。 尝试将 onclick="javascript:emailCurrentPage()" 和 href="#" 添加到该标签

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM