【问题标题】:Internal link in email?电子邮件中的内部链接?
【发布时间】:2013-04-19 06:51:08
【问题描述】:

如何在电子邮件中插入内部链接?

这是我在浏览器中打开的 html,在 gmail 中复制粘贴,将其发送给我自己并期望其内部链接能够正常工作:

<html>
  <body>
    <p><a href="#Title1" title="Click to go to Title 1">Birds</a></p>
    <p><a href="#Title2" title="Click to go to Title 2">Trees</a></p>
    <p><a href="#Title3" title="Click to go to Title 3">Flowers</a></p>
    <h4 id="Title1">Birds</h4>
    <p> There are many different birds. There are... </p>
    <h4 id="Title2">Trees</h4>
    <p> Trees have many different colors and branches... </p>
    <h4 id="Title3">Flowers</h4>
    <p> The Lignum Vitae is the national flower of Jamaica... </p>
  </body>
</html>

编辑

我将以下内容发送给我自己:

<html>
  <body>
    <p><a href="#Title1" title="Click to go to Title 1">Birds</a></p>
    <p><a href="#Title2" title="Click to go to Title 2">Trees</a></p>
    <p><a href="#Title3" title="Click to go to Title 3">Flowers</a></p>
    <h4 id="Title1"><a name="Title1">Birds</a></h4>
    <p> There are many different birds. There are... HOWEVER, it should be noted that Gmail appears to override the default browser/HTML functionality with JavaScript (and inserts a prefix into the named anchor and corresponding href so as not to interfere with its web interface). Consequently it seems that Gmail will only scroll to the named anchor if it is currently out of view - if it is already visible then no scroll occurs. HOWEVER, it should be noted that Gmail appears to override the default browser/HTML functionality with JavaScript (and inserts a prefix into the named anchor and corresponding href so as not to interfere with its web interface). Consequently it seems that Gmail will only scroll to the named anchor if it is currently out of view - if it is already visible then no scroll occurs.</p>
    <h4 id="Title2"><a name="Title2">Trees</a></h4>
    <p> Trees have many different colors and branches... HOWEVER, it should be noted that Gmail appears to override the default browser/HTML functionality with JavaScript (and inserts a prefix into the named anchor and corresponding href so as not to interfere with its web interface). Consequently it seems that Gmail will only scroll to the named anchor if it is currently out of view - if it is already visible then no scroll occurs. HOWEVER, it should be noted that Gmail appears to override the default browser/HTML functionality with JavaScript (and inserts a prefix into the named anchor and corresponding href so as not to interfere with its web interface). Consequently it seems that Gmail will only scroll to the named anchor if it is currently out of view - if it is already visible then no scroll occurs.</p>
    <h4 id="Title3"><a name="Title3">Flowers</a></h4>
    <p> The Lignum Vitae is the national flower of Jamaica... HOWEVER, it should be noted that Gmail appears to override the default browser/HTML functionality with JavaScript (and inserts a prefix into the named anchor and corresponding href so as not to interfere with its web interface). Consequently it seems that Gmail will only scroll to the named anchor if it is currently out of view - if it is already visible then no scroll occurs. HOWEVER, it should be noted that Gmail appears to override the default browser/HTML functionality with JavaScript (and inserts a prefix into the named anchor and corresponding href so as not to interfere with its web interface). Consequently it seems that Gmail will only scroll to the named anchor if it is currently out of view - if it is already visible then no scroll occurs.</p>
  </body>
</html>

并且链接不可点击。我做错了什么?

【问题讨论】:

    标签: email hyperlink


    【解决方案1】:

    gmail 中,您需要使用命名锚:

    <a name="Title1">Birds</a>
    

    如您所料,不同的电子邮件客户端...工作方式不同。有些支持 ID 的内部链接;有些没有;一些支持两者。 AFAIK gmail 仅支持 named 锚。请记住,可能会有一些电子邮件客户端根本不支持内部链接。

    h4 中的id 并不是绝对必要的,因为命名的锚点应该可以在大多数电子邮件客户端中使用。但是,据我所知,没有理由不同时拥有两者。以下内容在 Gmail 中适用于我:

    <h4 id="Title1"><a name="Title1">Birds</a></h4>
    

    但是,应该注意的是,Gmail 似乎用 JavaScript 覆盖了默认的浏览器/HTML 功能(并在命名的锚点和相应的 href 中插入了一个前缀,以免干扰其网络界面)。因此,Gmail 似乎只有在当前不在视野范围内时才会滚动到指定的锚点 - 如果它已经可见,则不会发生滚动。

    【讨论】:

    • 等等——那么&lt;h4&gt;应该是什么?你能举一个完整的例子吗?不能让它工作。
    • 据我所知,您可以保留h4。我已经更新了我的答案。请注意,由于 Gmail 似乎仅在目标不在视野范围内时才会滚动,因此您可能看不到示例中的滚动,除非您将视口变小或添加更多内容。 “在 gmail 中复制粘贴” - 大概你的意思不是直接将 HTML 复制粘贴到 Gmail 中?
    • 不——我在浏览器中打开 html,然后将其复制粘贴到 gmail。我不工作。我已经发布了我尝试过的完整 html。
    • 嗯,我对你的意思有点困惑......你如何“复制粘贴到 gmail”?如果这是您的暗示,您不能简单地将一大段 HTML 复制/粘贴到您在 Gmail 网络界面中撰写的电子邮件中? (Gmail 将对其进行转义并显示原始 HTML。)虽然我认为这不是您正在做的事情,因为您的某些 HTML 似乎被正确解释,否则您会问一个不同的问题。假设您使用服务器端脚本(例如 PHP)生成 HTML 电子邮件,我已经回答了您的问题。
    • 如果我将它发送到 Gmail 帐户,您的第二个代码示例(与编写的完全相同)对我来说可以正常工作。请记住,如果您使用其他电子邮件客户端发送电子邮件,那么这可能会更改消息的结构在发送之前
    猜你喜欢
    • 2013-10-04
    • 1970-01-01
    • 2016-06-24
    • 2013-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-22
    • 2011-09-03
    相关资源
    最近更新 更多