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

Q1673 When capturing a userid and password in a form can I subsequently use them when requesting a server page that requires HTTP authentication?

You are here: irt.org | FAQ | JavaScript | Form | Q1673 [ previous next ]

Try:

<script language="JavaScript"><!--
var userid = '';
var password = '';
var windowReference;

function promptForTwo() {
  var w = 480, h = 340;

  if (window.screen) {
    w = screen.availWidth;
    h = screen.availHeight;
  }

  var popW = 300, popH = 150;
  var leftPos = (w-popW)/2, topPos = (h-popH)/2;

  window.open('popup.htm','windowName','width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos);

  if (!windowReference.opener)
    windowReference.opener = self;
}

function done() {
  locattion.href = 'http://' + userid + ':' + password + '@www.yourserver.com/index.htm';
}

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

And then in popup.htm:

<html>

<head>

<script language="JavaScript"><!--
function prompts(form) {
  opener.userid = form.userid.value;
  opener.password = form.password.value;
  opener.done();
  self.close();
  return false;
}

function cancel() {
 self.close();
  return false;
}
//--></script>

</head>

<body onLoad="document.myform.userid.focus()">

<form name="myForm" onSubmit="return prompts(this)" onReset="cancel()">
Userid: <input type="text" name="userid">
<br>
Password: <input type="password" name="password">
<br>
<input type="submit" value="  ok  "> <input type="reset" value="  cancel  ">
</form>

</body>

</html>

Feedback on 'Q1673 When capturing a userid and password in a form can I subsequently use them when requesting a server page that requires HTTP authentication?'

©2018 Martin Webb