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

130
Visualizações
Store temporarily data on browser

Can we temporarily store data on browser ? For an example , i have page A and page B

On page A(a.html) , i would want to temporarily store text "Helloworld" on button click

function a(){
  return "helloWorld"
}

function changePage(){
  a()
  window.location(b.html)
}

On page B(B.html), i would want then to capture "Helloworld" on page A and print it on page b.

console.log(a())

I read on postMessage but based on my understanding , this only works on 2 page thats loaded on a single page on cross-domain workaround.

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

0

You can use the browser’s local-storage capabilities: localStorage. It helps to store data on the browser as strings.

To store data:

localStorage.setItem('foo', 'helloWorld');

To get the saved data:

localStorage.getItem('foo');// return 'helloWorld'
about 4 years ago · Juan Pablo Isaza Relatório

0

I think sessionStorage fits your purpose. But mind that the data is removed when the user closes the browser - if you don't want that, simply replace sessionStorage with localStorage. But as long as you don't need the data to be persistent across restarts you should rather use sessionStorage to not fill up the users disk:

a.html

window.addEventListener("load", function() { // this is executed when the site is loaded
  inputElement = document.getElementById("dataInput");
  inputElement.addEventListener("input", function() { // and this whenever the user changes the contents of dataInput
    window.sessionStorage.setItem("dataInput", inputElement.value());
  });
});
<input id="dataInput" type="text" placeholder="Enter your data">

b.html

window.addEventListener("load", function() {
  outputElement = document.getElementById("dataOutput");
  outputElement.setText(window.sessionStorage.getItem("dataInput"));
});
<p id="dataOutput">The data should appear here</p>

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