![](/img/trans.png)
[英]Using Javascript, I am trying to persist the data in SessionStorage and localStorage of browser but after refreshing the page the data is lost
[英]Pass array in JavaScript to another page without using sessionStorage or localStorage
有谁知道如何在不使用sessionStorage
或localStorage
情况下将array
值传递给另一个页面?
我认为你有一个页面; 您想通过单击第一页上的按钮将一些数据发送到另一页。 你可以这样做:
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 "";
}
}
你可以像这样使用这两个函数:
<button onclick="sendData("page.html", [1, 2, 3])">Redirect</button>
并且您可以通过在第二页中调用getData()
来获取数据。
您可以将数组传递给query string
。
这个问题可以帮助您: 如何在查询字符串中传递数组?
当您使用beforeunload
事件转到 b.html 时,您可以将 arry 放入 a.html 中的查询字符串中,然后使用DOMContentLoaded
事件在 b.html 中获取此数组。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.