简体   繁体   English

使用mailto Javascript将本地文件的链接添加到电子邮件中

[英]Add a link to a local file to email using mailto Javascript

I need to pass data from one html form to another through email. 我需要通过电子邮件将数据从一种HTML形式传递到另一种形式。 I'm having some issues inserting a link to a local file. 我在插入指向本地文件的链接时遇到了一些问题。 Once the outlook client opens, the link is not formatted correctly and is not a hyperlink. Outlook客户端打开后,链接的格式不正确,并且不是超链接。 This is my send() function from my form 这是我表单中的send()函数

function send() 
{
    var name = document.getElementById('Fname').value;
    var company = document.getElementById('company').value;
    var email = document.getElementById('email').value;
    var str = "Link to IT Web Report"
    var linkToReport = str.link('S:\IT\Applications\Aleds Work\Guest WIFI access\ITTaskWebReport.html?name='+name+'&company='+company+'&email='+email);
    var link = 'mailto:FHCNetAlert@fhc.co.uk?subject= Guest WIFI request'
             +'&body=A request for guest WIFI access was made. Details:- %0D%0A'
             +'%0D%0A Name: '+document.getElementById('Fname').value +
             '%0D%0A Company: '+document.getElementById('company').value +
             '%0D%0A Email: '+document.getElementById('email').value +
             '%0D%0A' +linkToReport;
    window.location.href = link;
}

This is how this link appears in Microsoft outlook - 这是此链接在Microsoft Outlook中的显示方式-

<a href="S:ITApplicationsAleds WorkGuest WIFI accessITTaskWebReport.html?name=Aled Hughes 

As you can see, its not the right format, its not a link, and its missing the company variable and also the email variable. 如您所见,它的格式不正确,不是链接,并且缺少公司变量和电子邮件变量。 Any help out there? 有什么帮助吗?

To pass URL's in mailto links you'll need to URLencode them, and you also want to escape your backslashes. 要在mailto链接中传递URL,您需要对其进行URL编码,并且还希望转义反斜杠。 I don't have a windows machine to hand to test, but you want something like; 我没有要测试的Windows机器,但是您想要类似的东西;

var linkToReport = str.link(encodeURIComponent('S:\\\\IT\Applications\\Aleds Work\\Guest WIFI access\\ITTaskWe...'))

That should hopefully set you on the right path ;) 这有望使您走上正确的道路;)

You'll need to use encodeURIComponent as in mailto URI's , GET-like parameters are interpreted as email headers such as body , cc , so it will break on the components in your URI like company . 您需要像在mailto URI中一样使用encodeURIComponent ,类似GET的参数被解释为电子邮件标头,例如bodycc ,因此它将破坏URI中像company一样的组件。

Also watch out for people with names like "O'Mally" ie add more logic to convert single quotes, as the MDN page on encodeURIComponent says; 也要当心诸如“ O'Mally”之类的人,即添加更多逻辑以转换单引号,正如encodeURIComponent上MDN页面所说;

encodeURIComponent escapes all characters except the following: alphabetic, decimal digits, - _ . encodeURIComponent会转义除以下字符外的所有字符:字母,十进制数字--_。 ! ~ * ' ( ) 〜*'()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 javascript-将js确认添加到mailto链接 - javascript - add a js confirm to mailto link Javascript将日期和时间添加到mailto主题链接 - Javascript add date and time to mailto subject link 根据选择,使用javascript将“ mailto:”链接更改为“ mailto:variable” - Based on selection, “mailto:” link changes to “mailto: variable” using javascript 如何使用 JavaScript 将签名添加到 Outlook email 中? - How can I add a signature into an Outlook email with JavaScript mailto? 如何在 mailto 链接中添加 JSON 文件中的数据? - How to add the data from a JSON file in a mailto link? 使用mailto URL将附件添加到新的Outlook电子邮件中 - Add an attachement to a new outlook email using mailto URL JavaScript是否可以通过单击按钮但不使用mailto:或表单操作来发送电子邮件? - Can JavaScript send an email by clicking a button but NOT using mailto: or a form action? 添加mailto:在每封电子邮件之前 - add mailto: before every email 基于多个复选框的选择,使用javascript将“ mailto:”链接更改为“ mailto:多个变量” - Based on Multiple checkbox selection, “mailto:” link changes to “mailto: multiple variables” using javascript 邮件中带有主题行的Mailto链接无法使用javascript - Mailto link in a message with a subject line not working using javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM