Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

148
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda