【问题标题】:Share the url by email (catch automatic the url)通过电子邮件分享网址(自动获取网址)
【发布时间】:2015-10-16 14:47:42
【问题描述】:
这就是我现在所拥有的。
我真的不擅长 Javascript,所以我不知道要在这里写什么。
但我需要一个脚本或其他东西,当您单击按钮时,它会自动从与您所在的页面相同的页面获取 url,并将其放入电子邮件的描述中。
<a href="mailto:?subject=Link til guide&amp;body=Du finder guiden her: http://www.website.com.">
【问题讨论】:
标签:
html
css
email
url
share
【解决方案1】:
删除href中的“http://www.website.com”,然后将其放在HTML底部但在结束</body>标签上方:
<script>
var els = document.querySelectorAll('a[href*=mailto]'), i;
for (i = 0; i < els.length; ++i) {
els[i].href += window.location.href; // Adds current URL
}
</script>
这将抓取所有带有“mailto”的锚标记,然后将当前 URL 添加到 href 属性的末尾。
var els = document.querySelectorAll('a[href*=mailto]'), i;
for (i = 0; i < els.length; ++i) {
els[i].href += window.location.href; // Adds current URL
}
<a href="mailto:?subject=Link til guide&amp;body=Du finder guiden her: ">test link</a>
注意:sn-p 中的代码添加的是 iframe 的 URL,而不是您在地址栏中看到的 URL。如果你在 iframe 中有这个,你将需要更复杂的逻辑