简体   繁体   English

当前html页面的“mailto”

[英]“mailto” of the current html page

I'm trying to generate an email in client side out of the current html page (to be more precise a div named "inc" inside my page).我正在尝试从当前 html 页面的客户端生成一封电子邮件(更准确地说,我的页面中名为“inc”的 div)。 i'm stuck in the very first steps where i have this code:我被困在我有这个代码的第一步:

    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>

When I press the link nothing happens, when debugging I can see the html code in "htmlData" variable.当我按下链接时,什么也没有发生,调试时我可以在“htmlData”变量中看到 html 代码。

Moreover, when I change the "htmlData" in the third row to some text like "bla bla" or even <html><body></body></html> the email is being opened normally.此外,当我将第三行中的“htmlData”更改为“bla bla”或什至<html><body></body></html>之类的文本时,电子邮件正在正常打开。

What can be the reason for the mailto not to work with htmlData ? mailto不能使用 htmlData 的原因是什么?

One more little question.还有一个小问题。 Do you think I am on the right way for sending an HTML page ?你认为我发送 HTML 页面的方式正确吗? Because I'm afraid I won't be able later to convert the HTML code to be seen as HTML page in the email.因为我怕以后无法将 HTML 代码转换为电子邮件中的 HTML 页面。

Its definently not cool to call a JS function with href.使用 href 调用 JS 函数肯定不是很酷。 You will also want to format your mailto: link.您还需要格式化您的 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>

I think it's not cool to href a function.我认为 href 一个函数并不酷。 Try adding onclick= "javascript:emailCurrentPage()" and the href ="#" to that tag尝试将 onclick="javascript:emailCurrentPage()" 和 href="#" 添加到该标签

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

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