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>