Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

203
Views
Send non executable script in body by mailto:

I want to prepare an email to send with mailto: This email contains a few words and a js script. This script does not need to be executed. It's just for the receiver to copy and paste.

The script :

<script id="myID">var script = document.createElement("script");script.src="script-to-inject.js?id=myID&type=0&name=Name&size=120";document.head.appendChild(script); </script>

And my mailto:

window.location.href = "mailto:"+email+"?subject="+subject+"&body=FewWords"+ script;

When my mail isopen i have something like that :

<script id="myID">var script = document.createElement("script");script.src="script-to-inject.js?id=myID

The end of the script does not appear (after the first &)

How can i fix this ? Thanks !

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You forgot to encode the URL parameters, so the & starts the next parameter.

You can use the encodeURIComponent function:

window.location.href = "mailto:" + encodeURIComponent(email) +
  "?subject=" + encodeURIComponent(subject) +
  "&body=" + encodeURIComponent("FewWords" + script);

Another, cleaner, way would be to use URLSearchParams:

const url = new URL(`mailto:${encodeURIComponent(email)}`)
url.searchParams.set('subject', subject)
url.searchParams.set('body', 'FewWords' + script)
window.location.href = url
about 4 years ago · Juan Pablo Isaza Report

0

You need to be escaping email, subject, and script properly when setting the href attribute. What if these variables contain the & or the = characters? You can see how this would get misinterpreted.

Try this:

window.location.href = "mailto:"
  + encodeURIComponent(email)
  + "?subject="
  + encodeURIComponent(subject)
  + "&body=FewWords"
  + encodeURIComponent(script);

(I'm not sure that you can pass HTML in the body parameter, by the way, it might get interpreted as plain text.)

You can also use URLSearchParams:

const params = new URLSearchParams();
params.append('subject', subject);
params.append('body', 'FewWords' + script);
window.location.href = 'mailto:' + encodeURIComponent(email) + '?' + params.toString();
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!