I can successfully pre-populate an email from a button click with the first part of the page URL, and the first parameter in the URL, but it’s cutting off after that. I have multiple parameters in the URL. How do I capture them all and put the full URL in the link in the email?
So for the url e.g. https://website.com/folder?param1=one¶m2=two
Current code:
<div class="button">
<a href="mailto:?subject=Email title&body=Here’s a link: [sub]" data-message=""
onclick=”this.href = this.href.replace(‘[sub]’,window.location)”>Email me a link to this page
This is populating the email link part with https://website.com/folder?param1=one only. ¶m2=two is missing.
I’ve also tried with
<div class="button">
<a href="mailto:?subject=Email title&body=Here’s a link: " data-message=""
onclick=”this.href += window.location.href;”>Email me a link to this page
Which has the same result.
I have a feeling it’s to do with needing to use URLSearchParams
and specify the parameter names, but I don’t know how to write this into the existing code. I read MDN but I’m a beginner so need help.
Thanks in advance.