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

149
Visualizações
One HTML page with multiple sessionStorage (Javascript)

I have several js-scripts like this;

function text1() { <!-- function name is in each first script different -->
    var nl1 = "text1"
    var nb1 = "text2."
    
    sessionStorage.clear();
    sessionStorage.setItem("nl1", JSON.stringify(nl1));
    sessionStorage.setItem("nb1", JSON.stringify(nb1));}

I have a second script who randomly calls one of these scrips and shows its content.

Now, I like to have a new page showing all the first scripts (around 30) together. Because the sessionStorage item is the same in each first scripts, I cannot get it to work.

<script>
function test() {
    var script = document.createElement('script');

    script.onload = function () {
        if ((jsarray = JSON.parse(sessionStorage.getItem("nl1"))) === null) {
            var nl1 = jsarray = JSON.parse(sessionStorage.getItem("nb1"));
        } else {
            var nl1 = jsarray = JSON.parse(sessionStorage.getItem("nl1"));
        }
        
        document.getElementById("tekst1").innerHTML = nl1;
    };

    script.src = "/../script1.js";
    
    document.head.appendChild(script);

}

function test2() {
    var script2 = document.createElement('script');

    script2.onload = function () {
        if ((jsarray = JSON.parse(sessionStorage.getItem("nl1"))) === null) {
            var nl1 = jsarray = JSON.parse(sessionStorage.getItem("nb1"));
        } else {
            var nl1 = jsarray = JSON.parse(sessionStorage.getItem("nl1"));
        }
        
        document.getElementById("tekst2").innerHTML = nl1;
    };

    script2.src = "/../script1.js"; 
    document.head.appendChild(script2);
}
</script>

<body onload="test(),test2()">

<p id="tekst1"></p>
<p id="tekst2"></p>

</body>
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