当前 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>
当我按下 link 时没有任何反应,在调试时我 可以 在“htmlData”变量中看到 html 代码。
此外,当我将第三行的“htmlData”更改为“bla bla”之类的文本时,甚至 <html><body></body></html>
电子邮件都可以正常打开。
mailto
不能使用 html 数据的原因是什么?
再问一个小问题。您认为我发送 HTML 页面的方式正确吗?因为我担心以后无法将 HTML 代码转换为在电子邮件中被视为 HTML 页面。
我认为 href 一个函数并不酷。尝试向该标签添加 onclick= "javascript:emailCurrentPage()" 和 href ="#"
用href调用一个JS函数肯定不爽。您还需要格式化您的邮箱:link.
<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>
我正在尝试在客户端从当前 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>
当我按下 link 时没有任何反应,在调试时我 可以 在“htmlData”变量中看到 html 代码。
此外,当我将第三行的“htmlData”更改为“bla bla”之类的文本时,甚至 <html><body></body></html>
电子邮件都可以正常打开。
mailto
不能使用 html 数据的原因是什么?
再问一个小问题。您认为我发送 HTML 页面的方式正确吗?因为我担心以后无法将 HTML 代码转换为在电子邮件中被视为 HTML 页面。
我认为 href 一个函数并不酷。尝试向该标签添加 onclick= "javascript:emailCurrentPage()" 和 href ="#"
用href调用一个JS函数肯定不爽。您还需要格式化您的邮箱:link.
<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>