将变量传递到新页面 [英] Pass a variable to new page

查看:68
本文介绍了将变量传递到新页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从一页传递变量,加载另一页并输入该信息. 像这样的东西:

I am trying to pass a variable from one page, load another and enter that information. something Like this:

当127.0.0.1/test.html&ID=1234

When 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,但希望将变量从另一个传递给他们.这可能吗?

I don't have access to modify 127.0.0.1/test.html nor newpage.html but would like to pass variables to them from another. Is this possible?

推荐答案

您可以在查询字符串中传递值,然后读取这些值:

You could pass the values on the query string and then read those:

location.href = "http://127.0.0.1/newpage.html?foo=1&bar=2";

然后使用location.search获取查询字符串并使用Javascript对其进行解析.只要确保没有任何查询字符串项与任何其他可能存在的冲突即可.

Then use location.search to get the query string and parse it with Javascript. Just make sure none of the query string terms collide with any others that may exist.

这篇关于将变量传递到新页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆