我正在使用 Javascript。我正在使用警报从用户那里获取密码。但是,您可能知道,警报不会将密码从其他“肩冲浪”中屏蔽掉。为了解决这个问题,我创建了一个页面,该页面只允许用户输入从父 javascript 页面打开的密码。问题是 javascript 在执行更多 javascript 指令之前不会等待用户输入密码。我的问题是,如何让我的 javascript 在执行下一条指令之前等待接收来自用户的信息?
下面的父页面是我正在使用的示例。由于我在网上阅读到您无法屏蔽 window.prompt 输入,因此决定尝试打开一个新窗口并让用户将其输入到 html 表单中。这是父级所需的最低限度的代码(真正的父级页面要长得多,与问题无关)。父页面:
<html>
<head>
<script language="javascript">
function start()
{
document.write("here");
var w = window.open('password.html','newWindow','width=550,height=170,left=150,top=200,toolbar=no,resizable=false');
var password = "holder value";
document.write(password);
}
</script>
<title>
Parent Window
</title>
</head>
<body onload="start()">
</body>
</html>
子页面:
<html>
<head>
<title>This is for the user to input their password</title>
<script language="javascript">
function Parent()
{
console.log("working");
//opener.document.form.parent_name.value = document.frm.child_name.value;
// opener.document.form.parent_name.value = document.Input.pwd.value;
opener.document.password= document.Input.pwd.value;
self.close();
}
</script>
</head>
<body>
<form name="Input" method="post" action="">
<input type="password" name="pwd">
<input type="button" value="Submit" onClick="Parent()">
</form>
</body>
</html>