0

Does anyone know how to pass an array value to another page without using sessionStorage or localStorage?

Vl4dimyr
  • 876
  • 9
  • 27
mo0n
  • 11
  • 3

2 Answers2

0

I take it that you have a page; you want to send some data to another page, by clicking in a button from the first page. You can do it like this:

function sendData(url, data) {
  window.location = url + "#" + JSON.stringify(data);
}


function getData() {
  if (window.location.hash == "")
    return "";
  try {
    return JSON.parse(window.location.hash.substr(1));
  } catch {
    return "";
  }
}

And you can use these two functions like this:

<button onclick="sendData("page.html", [1, 2, 3])">Redirect</button>

And you can get the data by calling getData() in the second page.

The Moisrex
  • 1,857
  • 1
  • 14
  • 16
0

You can pass the array into query string.

This question can help you: How to pass an array within a query string?

You can put the arry into query string in a.html when you go to b.html using beforeunload event, then you get this array in b.html using DOMContentLoaded event.

JackChouMine
  • 947
  • 8
  • 22