简体   繁体   中英

Appending url to the body of mailto

How to append location.href url in mailto body.

  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); url is printing correctly but in the mail body url is not getting appended - Its still blank body

I tried the below ones it append this in the 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

You need to use JavaScript for this. It looks like you're trying to embed JavaScript inside an HTML tag, which is not valid.

JavaScript code can be embedded in HTML tags in the form of event handlers. Examples include the onload , onclick , and onmouseover attributes. 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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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