重定向到另一个页面(在同一个域中)后是否可以保留我的 javascript 全局变量?
我知道我可以使用 html5 localStorage/sessionStorage 或将其存储在服务器会话状态中(稍后再拉)。但是当使用复杂的或更多的全局变量时,我想知道是否有另一种快速的使用方法......
例如:
<html>
<head>
<title> first page </title>
<script type="text/javascript">
var myGlobal="this is my global variable";
...
</script>
</head>
<body>
...
<a href="secondPage.htm" ..> to the second page</a>
</body>
</html>
在 secondPage.htm 中:
<html>
<head>
<title> second page </title>
<script type="text/javascript">
alert(myGlobal); //I want it to be : "this is my global variable";
...
</script>
</head>
<body>
...
</body>
</html>