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

166
Vistas
Replace pathname and origin using Javascript

I have a function where I get some data via a rest-call and put it into a div with an id schnittstelle-01.

const request = new XMLHttpRequest();
request.open(
    'GET',
    'https://purl.ulb.tu-darmstadt.de/vp/r000000-2001?ed=pa000008',
);
request.addEventListener('load', function (event) {
    if ((request.status = 200)) {
        document.getElementById('schnittstelle-01').innerHTML =
            request.responseText;
        console.log(request.responseText);
        for (let el of document.querySelectorAll('#schnittstelle-01 * a'))
            el.href = el.href.replace(
                window.location.origin,
                'purl.ulb.tu-darmstadt.de/vp/',
                
            );
    } else {
        console.log(request.status);
    }
});
request.send();

The retrieving part is not what bothers me, but the el.href.replace() part... Let's say my url is test.de the link are supposed to lead to purl.ulb.tu-darmstadt.de/vp/{link-target} at the moment the links after this point to purl.ulb.tu-darmstadt.de/vp/path-to-site-on-test.de/{link-target}

I cannot figure out how to replace both parts. Any hints would be appreciated! I think I'm missing sth. basic here ...

all the best,

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

you need location.pathname

el.href = el.href.replace(
    location.origin + location.pathname,
    'purl.ulb.tu-darmstadt.de/vp/',
 );
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