[英]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.