Does anyone know how to pass an array
value to another page without using sessionStorage
or localStorage
?
Asked
Active
Viewed 99 times
0
-
1cookie?????????????????? – Ishwar Patil Mar 23 '18 at 09:55
-
An "array" is very different from an "array value". – CertainPerformance Mar 23 '18 at 09:56
-
3Is this two pages that load one after the other? Or two pages in two tabs open at the same time? Or a main page and a popup window? Please be as specific as you can. – Peter B Mar 23 '18 at 09:56
-
stringy it and pass it through the query-string – Alexis Mar 23 '18 at 09:57
-
@PeterB the page is call one after another. For example, i click a button to redirect to another page. Then the array value i declare will pass the another page(to perform edit or delete the value inside the array) – mo0n Mar 23 '18 at 10:09
-
Are you using jquery? – Sunny Soni Mar 23 '18 at 11:05
-
@SunnySoni yes, javascript or jquery i have used – mo0n Mar 23 '18 at 16:19
2 Answers
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