【发布时间】:2013-01-18 19:53:52
【问题描述】:
重定向到另一个页面后是否可以保留我的 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>
【问题讨论】:
-
sessionstorage、localstorage 还是 cookie 怎么样?
标签: javascript