javascript - <a> 元素内的链接不起作用

标签 javascript jquery html

我不确定你们中的许多人是否尝试过这样做,而且我完全没有办法解决这个问题,但我们开始吧:

单击按钮后,会出现一封预制电子邮件 - 但电子邮件内的链接不是超链接!看看这个 - 我被迫这样做的方式是通过 javascript 进行控制,我将在稍后添加...

所以问题是,如何在电子邮件中放置超链接(那里的链接应该转到该链接)?

我想真正的问题是我如何将 html 放入 JavaScript 中......

工作 jsFiddle here .

HTML:

<a id = 'emailoff' href = "" target = "_blank">
    <div id= "btn1">
         <h2 id = "enter">Send Email</h2>
    </div>
</a>

JavaScript:

$('#btn1').click(function(){
                $("#emailoff").attr("href", "mailto:" +
                                    "?subject=Your ThinOptics glasses &body=To get your new ThinOptics glasses simply click this link and pick the case and color you like best.  You'll get  free shipping on your order.%0D %0D http://www.Thinoptics.com/teddy@shalon.com%0D %0D Enjoy")
            });

最佳答案

不同的电子邮件客户端会以不同的方式处理

mailto 链接。有些人可能会选择将以 http:// 开头的纯文本转换为超链接,而另一些人则不会。在许多情况下(邮件客户端、浏览器和设置的组合),mailto: 链接根本不起作用(我使用 Chrome 浏览器并使用没有安装专用 SMTP 客户端的 Gmail,并且 mailto: 对我来说根本不起作用)。

Mailto clickable links do not always function correctly for the site visitor. The software mechanism activated by the link requires that a default email client or webmail-service be established on the computer or in the browser. Not all web browsers, such as Internet Explorer, have the capability to configure a webmail service for this purpose, but only support local email client software. Others, such as Opera, Firefox, and Chrome, do have support for both variants.

Additionally, if no email client or webmail service has been explicitly established to act as the default, one may still exist if an email client was pre-installed by the computer vendor but never used or configured by the user. In this case, upon clicking a mailto link, the user will be subjected to a volley of technical questions by the unconfigured email client.

http://en.wikipedia.org/wiki/Mailto#Functionality_issues

此外,还有一些机器人会定期扫描网络以查找 mailto: 链接。预计该链接中指定的任何电子邮件地址都会收到大量垃圾邮件。

最后,确保对链接中所需的元素进行 URL 编码

[STD66] requires that many characters in URIs be encoded. This affects the 'mailto' URI scheme for some common characters that might appear in addresses, header fields, or message contents. One such character is space (" ", ASCII hex 20). Note the examples below that use "%20" for space in the message body. Also note that line breaks in the body of a message MUST be encoded with "%0D%0A". Implementations MAY add a final line break to the body of a message even if there is no trailing "%0D%0A" in the body of the 'mailto' URI. Line breaks in other s SHOULD NOT be used.

http://www.ietf.org/rfc/rfc6068.txt

关于javascript - <a> 元素内的链接不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23142728/

相关文章:

php - 网站。 AJAX 和 FIREFOX 问题。我认为 Firefox 不喜欢 ajax..?

javascript - 加载弹出窗口并填充来自点击链接的信息

javascript - 单击单元格,然后它仅在单元格下被选中我该怎么做

javascript - FileReader - 支持哪些编码?

html - Google Calendar API-403错误

使用枚举的 JavaScript 切换大小写

javascript - Highcharts 6 时间线图

javascript - Angular 4 复选框管道过滤器

javascript - 如果下拉列表中已经有一个 'onchange' 事件,如果我绑定(bind)另一个,它什么时候触发?

html - 如何在图像和文本之间创建一条水平线