javascript - 将变量传递到新页面

标签 javascript greasemonkey userscripts

我试图从一个页面传递一个变量,加载另一个页面并输入该信息。 像这样的东西:

当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/

相关文章:

javascript - ExtJS::如何过滤网格中的行,但不过滤存储中的行

javascript - Durandal widget destory 方法或类似的东西

javascript - 使用javascript保存XHR文件

javascript - 如何从 JavaScript 中的 URL 字符串中提取值?

javascript - Greasemonkey- 从搜索引擎结果页面中随机挑选单词

javascript - Angular ui-select 多个干净的 ng-model 值

javascript - 为什么 ~5 === -6 在 JavaScript 中?

javascript - 如何在 Greasemonkey 中替换链接的目标?

javascript - 为什么来自用户脚本的窗口(和 unsafeWindow)与来自 <script> 标签的窗口(和 unsafeWindow)不同?

javascript - 使用类向网站添加元素