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

197
Visualizações
Change <img> source after window.location.replace

When I press a button on my main page, it retrieves a link to an image using an api. Then I want to redirect to another page of mine and change the src attribute to the link i fetched with the api (on the new page).

Everything works besides the change image source.

Main page button:

<button onclick="search()" class="submit-button">SEARCH</button>

Java Script (Edit: JavaScript is stored in separate file 'script.js')

function search() {
    const username = document.getElementById("username").value

    // API CALL HERE WHICH CALLS presentImg()

}

function presentImage(url) {
    console.log(url)
    window.location.replace("profile.html")

    document.getElementById("image").src = url;

}

Profile.html

<img id="image" src="#">

When I open the main page and click the button I am redirected and the profile.html page opens but the image is not displayed. I have already checked the url, it works and shows only one image. I also tried to load a local image in my project folder, that doesn't work either.

about 4 years ago · Juan Pablo Isaza
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