简体   繁体   English

如何将值从一个html页面传递到另一个html页面javascript?

[英]How to Pass values form One html Page to Another html Page javascript?

How can I pass values from one html page to another html page javascript 如何将值从一个html页面传递到另一个html页面javascript

For example: 例如:

Page1.html page Page1.html页面

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
  <title>arasu</title>
  <style type="text/css">
  #popupbox{
  margin: 0; 
  margin-left: 40%; 
  margin-right: 40%;
  margin-top: 50px; 
  padding-top: 10px; 
  width: 20%; 
  height: 150px; 
  position: absolute; 
  background: #FBFBF0; 
  border: solid #000000 2px; 
  z-index: 9; 
  font-family: arial; 
  visibility: hidden; 
  }
  </style>
  <script language="JavaScript" type="text/javascript">
  function login(showhide){
    if(showhide == "show"){
        document.getElementById('popupbox').style.visibility="visible";
    }else if(showhide == "hide"){
        document.getElementById('popupbox').style.visibility="hidden"; 
    }
  }
  </script>
</head>
<body>
<div > 
<form name="login" action="AgaramAnimation.html" method="get">
<center>Username:</center>
<center><input name="username" size="14" /></center>
<center>Password:</center>
<center><input name="password" type="password" size="14" /></center>
<center><input type="submit" name="submit" value="login" /></center>
</form>
</div> 
</body>
</html>

here i enter two values user name and password when i click submit button the popup will closed and values pass to another page java script given below . 在这里我输入两个值用户名和密码,当我点击提交按钮时,弹出窗口将关闭,值传递给下面给出的另一个页面java脚本。

Page2.html Page2.html

function gettingvalues()
         {            
            var connection = new ActiveXObject("ADODB.Connection");
            var connectionstring = "Data Source="";Initial Catalog="";User ID="";Password="";Provider=""";
            connection.Open(connectionstring);
            var rs = new ActiveXObject("ADODB.Recordset");
            rs.Open("select * from logindetails where username='" **+ username +** "' and password= '" **+ password +** "'", connection);
            if (!rs.eof) {
                document.getElementById("").innerHTML = "";   }
            else {
                alert('please enter valid username and password');
            }
            connection.close;
        }

Pls help me.......... 请帮助我..........

Assuming your two pages are on the same domain, you can use localStorage. 假设您的两个页面位于同一个域中,则可以使用localStorage。

Popup.html: Popup.html:

var user = prompt('user name', '');
var password = prompt('password', '');
localStorage.user = user;
localStorage.password = password;

Then back in the main page: 然后回到主页面:

var user = localStorage.user;
var password = localStorage.password;

Note 1 : I won't comment on security (other than to say of course don't do it like I've done it above!) 注1 :我不会评论安全性(除了说当然不要像我上面那样做!)

Note 2 : localStorage is only about 92% supported: http://caniuse.com/namevalue-storage 注2 :localStorage仅支持约92%: http//caniuse.com/namevalue-storage

If Main.html has opened Popup.html with window.open() , then the Popup.html page can have a reference to its opening window (the window of Main.html ) using window.opener . 如果Main.html使用window.open()打开Popup.html ,则Popup.html页面可以使用window.opener引用其打开窗口( Main.html的窗口)。 It could thus call a setCredentials callback function defined in Main.html using 因此它可以调用Main.html定义的setCredentials回调函数

window.opener.setCredentials(...);

Example: 例:

in Main.html: 在Main.html中:

// callback function called by the popup
function setCredentials(login, password) {
    // do what you want with the login and password
}

in Popup.html 在Popup.html中

// function called when the form is submitted
function login(login, password) {
    window.opener.setCredentials(login, password);
    window.close();
}

You can refer to the window that opened your new window (called the parent window) via window.parent and then execute your javascript using that object. 您可以通过window.parent引用打开新窗口的窗口(称为父窗口),然后使用该对象执行您的javascript。

Here is an example of forcing a parent page to refresh using this: [1]Forcing parent page refresh through javascript 以下是使用此命令强制父页面刷新的示例: [1]强制通过javascript刷新父页面

So in your case you could have say variables for username and password in your js like this and you could set them in the popup window like so: 所以在你的情况下,你可以在你的js中说出用户名和密码的变量,你可以在弹出窗口中设置它们,如下所示:

//parent window
username = "";
password = "";

....

//popup window
window.parent.username = enteredUsername;
window.parent.password = enteredPassword;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何仅使用JavaScript将表单数据从一个HTML页面传递到另一HTML页面? - How do I pass form data from one HTML page to another HTML page using ONLY javascript? 如何使用javascript将值从一个html页面传递到另一个html页面 - How can I pass values from one html page to another html page using javascript 如何使用HTML表单将JavaScript值传递到另一个PHP页面? - How can I pass JavaScript values to another PHP page using an HTML form? 如何在JavaScript中将值从一个html页面传递到另一个页面? - How to pass value from one html page to another in JavaScript? 如何将javascript / jquery函数从一个HTML页面传递到另一HTML页面 - How to pass a javascript/jquery function from one html page to another 如何将 javascript 变量值从一个 html 页面传递到另一个 html 页面? - How to pass the javascript variable value from one html page to the another html page? 如何将此值传递给javascript并在HTML页面上按1显示1? - How to pass this values to javascript and display 1 by 1 on HTML page? 如何将数组从一个HTML传递到另一个HTML页面? - how to pass an array from one html to another html page? 如何使用html将值传递到另一个页面 - how to pass value one page to another page using html 如何将数据从一个页面传递到另一个页面html - How to pass data from one page to another page html
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM