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

205
Vistas
Update an image using with value from a URL parameter in jQuery or JS?

What I'm trying to do is getting a JS parameter to replace an image SRC with a custom URL using a URL parameter.

Example of parameter:

https://example.com?i=https://example.org/img.jpg
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

There are a few ways to do this and I hope this gets you started (I have not tested this code):

function getUrlVars () {
    let vars = {};
    const p = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,k,v) {
      vars[k] = v;
    });
    return vars;
}

const src = getUrlVars('i');
const img = document.getElementById('image-id-here');
img.src = src;

The getUrlVars is a generic function I often use. It's likely more complicated than what you need.

A word of waring; you should do the extra work/research to validate the content of the URL parameter before inserting into into your page.

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