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

175
Vistas
Add variable inside document.write()

I am trying to embed iframe using javascript but the "referrerpath" variable is not working inside the document.write() I am new to javascript, how to fix it? thanks

var referrerpath = document.referrer.replace(/^[^:]+:\/\/[^/]+/, '').replace(/#.*/, '').replace(/\?.*/, '');
    document.write("<iframe src='https://example.com/embed/' + referrerpath + style='border:none;width:100%;min-height:400px;'></iframe>");
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You can use template literals. You need to use backticks ( ` ) in order to use them.

var referrerpath = document.referrer.replace(/^[^:]+:\/\/[^/]+/, '').replace(/#.*/, '').replace(/\?.*/, '');
document.write(`<iframe src='https://example.com/embed/${referrerpath}' style='border:none;width:100%;min-height:400px;'></iframe>`);
about 4 years ago · Juan Pablo Isaza Denunciar

0

You aren't closing the string before concatenating it with your variable:

"<iframe src='https://example.com/embed/" + referrerpath + "' style='border:none;width:100%;min-height:400px;'></iframe>"

You could also use a template literal

`<iframe src='https://example.com/embed/${referrerpath}' style='border:none;width:100%;min-height:400px;'></iframe>`
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