Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q280 How can I capture a login name and password in a popup window and then pass it onto the next page?

You are here: irt.org | FAQ | JavaScript | Password | Q280 [ previous next ]

initial.html:

<script language="JavaScript"><!--
var loginname = '';
var loginpassword = '';

function windowOpen() {
    var myWindow=window.open('popup.html','windowRef','width=200,height=200');
    myWindow.location.href = 'popup.html';
    if (!myWindow.opener)
        myWindow.opener = self;
}

function go(url) {
    location.href = url + '?' + loginname + '&' + loginpassword;
}

windowOpen();
//--></script>

<a href="javascript:go('nextpage.html')">go to next page</a>

popup.html:

<script language="JavaScript"><!--
function returnDetails() {
    opener.loginname = document.myForm.loginname.value;
    opener.loginpassword = document.myForm.loginpassword.value;
    self.close();
}
//--></script>

<form name="myForm">
Name: <input type="text" name="loginname">
Password: <input type="password" name="loginpassword">
<input type="button" value="enter" onClick="returnDetails()">
</form>

nextpage.html:

<script language="JavaScript"><!--
var start = location.search.indexOf('?');
var end   = location.search.indexOf('&');
var loginname = location.search.substring(start+1,end);
var loginpassword = location.search.substring(end+1);

alert('Name = ' + loginname + '\n' + 'Password = ' + loginpassword);
//--></script>

©2018 Martin Webb