【问题标题】:Share the url by email (catch automatic the url)通过电子邮件分享网址(自动获取网址)
【发布时间】:2015-10-16 14:47:42
【问题描述】:

这就是我现在所拥有的。 我真的不擅长 Javascript,所以我不知道要在这里写什么。

但我需要一个脚本或其他东西,当您单击按钮时,它会自动从与您所在的页面相同的页面获取 url,并将其放入电子邮件的描述中。

<a href="mailto:?subject=Link til guide&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
    }
    &lt;a href="mailto:?subject=Link til guide&amp;amp;body=Du finder guiden her: "&gt;test link&lt;/a&gt;

    注意:sn-p 中的代码添加的是 iframe 的 URL,而不是您在地址栏中看到的 URL。如果你在 iframe 中有这个,你将需要更复杂的逻辑

    【讨论】:

      猜你喜欢
      • 2017-04-29
      • 2018-04-09
      • 1970-01-01
      • 1970-01-01
      • 2013-09-07
      • 2017-11-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-26
      相关资源
      最近更新 更多