当我们在其他页面使用 getGlobalVar("language") 时,它必须给出改变后的值
Web 使用无状态协议,即信息不会在页面之间持续存在。为了解决这个问题,您可以在客户端或服务器端解决方案(如会话)上使用 cookie。
尝试这个:
1.htm
<script type="text/javascript">
window.val = "hello world";
alert(window.val);
window.location.href = "2.htm"
</script>
2.htm
<script type="text/javascript">
alert(window.val);
</script>
饼干示例:
1.htm
<script type="text/javascript">
var in_one_year = new Date();
in_one_year.setFullYear(in_one_year.getFullYear() + 1);
document.cookie = "language=English" +
";expires=" + in_one_year.toGMTString();
all_cookies = document.cookie
alert(all_cookies);
window.location.href = "2.htm"
</script>
2.htm
<script type="text/javascript">
alert(document.cookie);
</script>