简体   繁体   English

使用javascript将用户输入的值传递到另一个html页面,并使用javascript函数重定向

[英]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页面,要求用户输入以下内容

  1. username and password click submit to redirect to load.html 用户名和密码,单击提交以重定向到load.html
  2. no input, but click on generate ID, automatically redirect to load.html 无输入,但单击生成ID,自动重定向到load.html
  3. input unique id, and redirect to load.html 输入唯一的ID,然后重定向到load.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.

相关问题 使用HTML和JavaScript将href值传递到另一个页面 - Passing href value to another page using html and javascript 使用javascript将值传递到另一个页面 - passing value to another page using javascript 将值从一个html页面传递到另一个html javascript函数 - passing the value one html page to another html javascript function 是否可以使用 JavaScript 和 HTML 在不清除页面历史记录的情况下将用户重定向到另一个页面? - Is it possible to redirect a user to another page without clearing their history of the page using JavaScript & HTML? 使用javascript重定向到html页面 - redirect to html page using javascript 将用户 HTML 输入作为 javascript function 参数传递 - Passing user HTML input as javascript function argument 其他功能完成后,使用javascript重定向到另一个页面 - Redirect to another page using javascript after another function finishes 如何使用控制器动作使按钮将页面重定向到另一个页面,并使用javascript传递值? - How can I make a button redirect my page to another page using a controller action and passing a value using javascript? 使用javascript将值从php页面传递到html页面 - passing value from a php page to html page using javascript 如何使用php中的javascript将用户重定向到另一个页面? - How to redirect user to another page using javascript in php?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM