Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

146
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!