Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

165
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda