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

172
Visualizações
javascript: localStorage.getItem() returns value on same page, returns null on next page

Sorry for this easy question:

I am doing:

  localStorage.setItem("eventID", product); // set item to a storage so that we can retrive next page 
  var tests = localStorage.getItem('eventID');

  console.log(tests)

I can see in the console that it retrieves the value I stored into it.

Now when I am on the next page:

var eventID = localStorage.getItem('eventID');
console.log(eventID)

It is returned as null.

How can that be?

This is how I move to the next page:

<p class="regText">Please sign in with your account. If you haven't used the app <a href="page_createAcc.html">click here.</a></p>

Edit this is the full code:

Page1:

getURLArguments();

function getURLArguments(){


  const queryString = window.location.search;
  const urlParams = new URLSearchParams(queryString);
  const product = urlParams.get('eventID')

  localStorage.setItem("eventID", product); // set item to a storage so that we can retrive next page 
 
}

( I can see it working with console, so the issue is not with the arguments)

Page 2:

getEventID();

function getEventID(){
  var eventID = localStorage.getItem('eventID');
  console.log(eventID)

}

The page change comes from html (see above).

I tried running this within single folder and on server. Neither works.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I found out that above code is working fine on Safari but not on Firefox. It works on firefox, only when the pages are hosted live. On a local machine, it just didnt work. But the code is correct.

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