我试图从一个页面传递一个变量,加载另一个页面并输入该信息。 像这样的东西:
当127.0.0.1/test.html&ID=1234
location.href = "127.0.0.1/newpage.html"
if (location.href == newpage.html){
var e = document.GetElementById("Loginbx");
e.Value = ID
}
我无权修改 127.0.0.1/test.html 或 newpage.html,但想将变量从另一个传递给它们。这可能吗?
最佳答案
您可以传递查询字符串上的值,然后读取这些值:
location.href = "http://127.0.0.1/newpage.html?foo=1&bar=2";
然后使用location.search获取查询字符串并用Javascript解析它。只需确保查询字符串术语不会与可能存在的任何其他术语发生冲突。
关于javascript - 将变量传递到新页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3016449/