[英]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的参数被解释为电子邮件标头,例如body
, cc
,因此它将破坏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.