简体   繁体   English

将URL添加到mailto的主体

[英]Appending url to the body of mailto

How to append location.href url in mailto body. 如何在mailto正文中附加location.href url。

  appendToUrl3 =window.location.href;
 <a href="mailto:googlehelp_r@gmail.com?Subject=Help%20Google-%20Results&body="+appendToUrl3 >GoogleResults</a>

When i do console.log(appendToUrl3); 当我做console.log(appendToUrl3); url is printing correctly but in the mail body url is not getting appended - Its still blank body url正确打印但在邮件正文中url没有被附加 - 它仍然是空白的主体

I tried the below ones it append this in the body +appendToUrl3 我尝试了下面的内容,它将它附加在body + appendToUrl3中

 <a href="mailto:googlehelp_r@gmail.com?Subject=Help%20Google-%20Results&body=+appendToUrl3">GoogleResults</a>

Please help to append the url in the body of mailto 请帮助将url添加到mailto的正文中

You need to use JavaScript for this. 你需要使用JavaScript。 It looks like you're trying to embed JavaScript inside an HTML tag, which is not valid. 看起来您正在尝试将JavaScript嵌入到HTML标记中,这是无效的。

JavaScript code can be embedded in HTML tags in the form of event handlers. JavaScript代码可以以事件处理程序的形式嵌入HTML标记中。 Examples include the onload , onclick , and onmouseover attributes. 示例包括onloadonclickonmouseover属性。 More on events . 更多关于事件

There are much more maintainable ways to do this, but here is a quick and dirty solution, using the onclick event handler: 还有容易维护的方式来做到这一点,但这里是一个快速和肮脏的解决方案,使用onclick事件处理程序:

<a href="mailto:googlehelp_r@gmail.com?Subject=Help%20Google-%20Results&body=" onclick="this.href+=escape(window.location.href)">GoogleResults</a>

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM