Are you looking for the prompt
function?
var response = prompt("What is your name?");
alert("Hello, " + response);
The dialog will look something like this:
This this probably isn't the best way to get password input, because it does not mask the input. Instead, consider using an HTML form with a password input field.
Maybe you are looking for basic HTTP authentication instead?
You can set this by getting your web server to send a few headers; for example with PHP:
<?php
if (!isset($_SERVER['PHP_AUTH_USER'])) {
header('WWW-Authenticate: Basic realm="My Realm"');
header('HTTP/1.0 401 Unauthorized');
echo 'Text to send if user hits Cancel button';
exit;
} else {
echo "<p>Hello {$_SERVER['PHP_AUTH_USER']}.</p>";
echo "<p>You entered {$_SERVER['PHP_AUTH_PW']} as your password.</p>";
}
?>
This will cause the client to show a dialog like this:
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…