1

And my code goes as below which breaks at the JS code snippet when the mail box opens.

<a href="mailto:?subject=This is My Subject&body=Hithis is my text and my page url is"+window.location.href+\" click link to see Greater experienceto" target="_top" class="">

Email

Where as i wanted it to display the url dynamically where the link is available in the page.Expected email

krish kr
  • 857
  • 1
  • 6
  • 7
  • Breaks how? Is there an error from your console or logger? Does `window.href` have to be escaped because it contains things that don't belong in a URL? –  Aug 09 '17 at 17:44
  • @jdv Just updated the question. where i am expecting the dynamic url page link output as `Hithis is my text and my page url is **(h ttp://mydomain.com/mypage)** click link to see Greater experienceto ` – krish kr Aug 09 '17 at 17:55
  • Use the debugger in any browser to inspect `window.location.href` to see what it is set to. BTW, I think this question is a duplicate of: https://stackoverflow.com/q/17863986/1531971 –  Aug 09 '17 at 18:06
  • Nope, The question is including a Page URL in the mail to body text. – krish kr Aug 09 '17 at 18:30
  • Note the comment about using `encodeURIComponent`. At any rate, you need to debug your code because no one here wants to do that. Is the thing you are referencing and hoping is a String to be concatenated to URL actually set to anything interesting? Proceed from the known to the unknown. –  Aug 09 '17 at 18:32

2 Answers2

1

Try it this way:

<a href="#" onclick="javascript:window.location='mailto:?subject=Interesting information&body=I thought you might find this information interesting: ' + window.location + ' click link to see Greater experienceto'">Click</a>
Robby
  • 843
  • 3
  • 19
  • 53
0


Your browser might not might support. have you tried updating your browser or reinstalling? Cross browser testing will always have problems when you are implementing inbuild functions. For myself . i will always build my own form to avoid these kind of circumstances. its long winded concept but always safest and will save more time in the future. for an example ... Creating your own mail form ..`dds

<form action="mailto:someone@example.com" method="post" enctype="text/plain">
Name:<br>
<input type="text" name="name"><br>
E-mail:<br>
<input type="text" name="mail"><br>
Mail:<br>
<input type="text" name="email" style="width:600px; height: 100px"><br><br>
<input type="submit" value="Send">
<input type="reset" value="Reset">
</form>

`

Try this. I hope it will help.. If you want to be exactly the same as the one you posted above. you just need to do some styling. what i would recommend is to add a div and wrap the form in it. so for example.

<div id="main-container">
  <form>..
  ..
  ..
  ..
  </form>
</div>

Cheers. :)