【发布时间】:2014-09-02 08:56:17
【问题描述】:
我想知道是否有任何方法可以通过.html 文件传递vars。
例如在我的index.html 和<a> 中点击设置:
var value = 'some text here';
并链接到other.html。
我的other.html 中第一个执行的脚本是:
console.log(value);
HTML 文件可以通过这种方式传递变量吗?
【问题讨论】:
-
使用 URL 或 cookie。如果是 URL,则访问
location.search或location.hash -
尝试将 other.html 打开为“other.html#yourVariableValue”,然后在 other.html 中 var value = window.location.hash;
-
@AbdulJabbar 谢谢,效果很好!
标签: javascript html var