[英]How can I pass values from one html page to another html page using javascript
In first page im getting value in textbox i need to pass it to another page which is divided into 2 frames. 在第一页中我在文本框中获取值我需要将其传递给另一个分为2帧的页面。 I need to display that value in first frame's html page.
我需要在第一帧的html页面中显示该值。 Please provide me a simple example.
请给我一个简单的例子。 I tried with window.document.getElementById("inputbox1").value but im unable to get the value.
我尝试使用window.document.getElementById(“inputbox1”)。value但我无法获取值。
Please provide me a simple example. 请给我一个简单的例子。
I would go with localStorage, as @MicrosoftGoogle propose, but is not well supported yet, you can use pure javascript to achieve this. 我会选择localStorage,就像@MicrosoftGoogle提议的那样,但是还没有得到很好的支持,你可以使用纯javascript来实现这一点。 You will have something like this on your form page:
您将在表单页面上看到类似的内容:
<form action="param-received.html" method="GET">
<input type="text" id="foo" name="foo">
<input type="submit" value="Send" name="submit" id="submit">
</form>
Once you click on Send button,you will be redirect to /param-received.html?foo=hola&submit=Send
. 点击“发送”按钮后,您将重定向到
/param-received.html?foo=hola&submit=Send
。
location.search
attribute contains the chain of parameters. location.search
属性包含参数链。 Here is the complete code to process data sent on param-received.html
: 以下是处理
param-received.html
上发送的数据的完整代码:
<script language="JavaScript">
function processForm()
{
var parameters = location.search.substring(1).split("&");
var temp = parameters[0].split("=");
l = unescape(temp[1]);
alert(l); //Dialog with the text you put on the textbox
}
processForm();
</script>
if url parameters are an option you could use this 如果url参数是一个选项,你可以使用它
function getParameter(param) {
var val = document.URL;
var url = val.substr(val.indexOf(param))
var n=parseInt(url.replace(param+"=",""));
alert(n+1);
}
getParameter("page");
ref http://bloggerplugnplay.blogspot.in/2012/08/how-to-get-url-parameter-in-javascript.html 参考http://bloggerplugnplay.blogspot.in/2012/08/how-to-get-url-parameter-in-javascript.html
another might be cookies 另一个可能是饼干
was beaten to the cookie part :p 被殴打到饼干部分:p
edit indeed not a good cookie reference this one is better http://www.w3schools.com/js/js_cookies.asp 编辑确实不是一个好的cookie参考这个更好http://www.w3schools.com/js/js_cookies.asp
function getValue(varname)
{
var url = window.location.href;
var qparts = url.split("?");
if (qparts.length == 1)
{
return "";
}
else{
var query = qparts[1];
var vars = query.split("&");
var value = "";
for (i=0;i<vars.length;i++)
{
var parts = vars[i].split("=");
if (parts[0] == varname)
{
value = parts[1];
break;
}
}
value = unescape(value);
// Convert "+"s to " "s
value.replace(/\+/g," ");
return value;
}
}
var VariableGot = getValue(YourPassingVariableName);
Just copy the function into your html file and pass your variable name to the function which is send through GET Method.Now You will get the value of the variable from url. 只需将函数复制到您的html文件中,并将您的变量名称传递给通过GET Method.Now发送的函数。您将从url获取变量的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.