我是node.js的新手。 我有两个html文件和一个共享的common.js。 在index1.html中,当点击锚点按钮时,它会调用common.js(它更新测试变量)的changetest()函数。 现在我想在index2.html中使用更新后的变量。 但是index2.html选择了测试的原始值。 (这可能是因为在新页面index2.html重新加载common.js) 请帮助什么可以是在index2.html中传递和接收测试值的好方法。什么是访问nodejs中两个html文件之间的共享javascript变量的最佳方式
Index1.html
<html>
<head>
<script type="text/javascript" src="common.js"></script>
</head>
<body>
<h1>Sample Page</h1>
<a href="index2.html" onclick="changetest()">Navigate</a>
</body>
</html>
common.js
var test="abc";
function changetest(){
test = "xyz";
}
index2.html
<html>
<head>
<script type="text/javascript" src="common.js"></script>
</head>
<body>
<h1>Sample Page2</h1>
<a href="#"><script>document.write(test)</script></a>
</body>
</html>
http://stackoverflow.com/questions/3737062/managing-sessions-in-node-js – RobE