Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

207
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda