[英]Passing value input by user to another html page using javascript and redirect using javascript function
I have a html page that ask user to input the following 我有一个html页面,要求用户输入以下内容
However, I know I need to store the either username and password, or the unique id. 但是,我知道我需要存储用户名和密码或唯一ID。 I have tried the following 我尝试了以下
var user = document.getElementById("username");
var password = document.getElementById("password");
localStorage.user = user;
localStorage.password = password;
and I try to use that in load.html through the following 我尝试通过以下方式在load.html中使用它
var user = localStorage.user;
but I have no idea how to get the user input using the variable. 但我不知道如何使用变量获取用户输入。 In addition is there a way I can redirect to another web page using a function rather than form? 另外,有没有一种方法可以使用函数而不是表单重定向到另一个网页?
Thanks in advance 提前致谢
function connector_id()
{
var id_ =document.getElementById("id")
id_.innerHTML=Math.floor((Math.random()*100000000)+100000000);
return id_;
}
var user = document.getElementById("username");
var password;
localStorage.user = user;
localStorage.password = password;
</script>
<form action = "load.html" method = "post">
Username: <input type = "text" name = "username" id="username"/>
<br />
Password: <input type = "password" name = "pass" />
<br />
<input type = "submit" value = "Submit">
</form>
<p id ="id"></p>
<button onclick="connector_id()">generate</button>
</p>
<form action = "load.html" method = "post">
ID: <input type = "text" name = "username" />
<input type = "submit" value = "Submit">
</form>
For this kind of stuff you have to use a server-side language (PHP, ASP, etc.) as you can pass variables thru files and so forth. 对于此类内容,您必须使用服务器端语言(PHP,ASP等),因为您可以通过文件等传递变量。
Doing this with HTML/JS only is going to get you in trouble as you are basically giving the user, pass and id to anyone openly. 仅使用HTML / JS这样做会给您带来麻烦,因为您基本上是在公开地向任何人提供用户,密码和ID。
Have a look here: PHP Codecademy.com 在这里看看: PHP Codecademy.com
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.