admin管理员组

文章数量:1289363

How can I pass values from one html page to another html page javascript

For example:

Page1.html page

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    ".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 .

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..........

How can I pass values from one html page to another html page javascript

For example:

Page1.html page

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3/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 .

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..........

Share Improve this question edited Dec 18, 2011 at 10:10 Raj asked Dec 18, 2011 at 9:26 RajRaj 4873 gold badges11 silver badges24 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 2

Assuming your two pages are on the same domain, you can use localStorage.

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 ment on security (other than to say of course don't do it like I've done it above!)

Note 2: localStorage is only about 92% supported: http://caniuse./namevalue-storage

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.

Here is an example of forcing a parent page to refresh using this: [1]Forcing parent page refresh through 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:

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

....

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

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. It could thus call a setCredentials callback function defined in Main.html using

window.opener.setCredentials(...);

Example:

in Main.html:

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

in Popup.html

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

本文标签: How to Pass values form One html Page to Another html Page javascriptStack Overflow