打开另一个页面-HTML/Javascript
这是我的全部html代码, 我不明白为什么它不打开“example.html”页面。 如果有人能帮我理解为什么。 我想确保当凭证正确并且我按下登录按钮时,它会将我指向一个新文件(在本例中为“example.html”),但我不知道为什么什么都没有发生打开另一个页面-HTML/Javascript,javascript,html,login,Javascript,Html,Login,这是我的全部html代码, 我不明白为什么它不打开“example.html”页面。 如果有人能帮我理解为什么。 我想确保当凭证正确并且我按下登录按钮时,它会将我指向一个新文件(在本例中为“example.html”),但我不知道为什么什么都没有发生 <html> <head> <title>Login</title> <link rel="stylesheet" href="css/css1.css"> &l
<html>
<head>
<title>Login</title>
<link rel="stylesheet" href="css/css1.css">
<script type="text/javascript">
var message = "Right Click Disabled!";
function rtclickcheck(keyp) {
if (navigator.appName == "Netscape" &&
keyp.which == 3) {
alert(message);
return false;
}
if (navigator.appVersion.indexOf("MSIE") != -1 && event.button == 2) {
alert(message);
return false;
}
}
document.onmousedown = rtclickcheck;
function check(form) {
if (form.username.value == "admin" && form.password.value == "123") {
window.open("example.html")
} else {
alert("Username Or Password Doesn't Match!");
}
}
</script>
</head>
<body>
<div class="form-box">
<div class="head">LOGIN</div>
<div id="textbox">
<form>
<input type="text" placeholder="Username" name="username">
<br>
<input type="password" placeholder="Password" name="password">
<br>
<input type="submit" onclick="check(this.form)" name="btn_submit" value="Login">
</form>
</div>
</div>
</body>
</html>
登录
var message=“右键单击已禁用!”;
功能RTCLICK检查(keyp){
如果(navigator.appName==“Netscape”&&
keyp.which==3){
警报(信息);
返回false;
}
if(navigator.appVersion.indexOf(“MSIE”)!=-1&&event.button==2){
警报(信息);
返回false;
}
}
document.onmousedown=rtclickcheck;
功能检查(表格){
if(form.username.value==“admin”&&form.password.value==“123”){
window.open(“example.html”)
}否则{
警报(“用户名或密码不匹配!”);
}
}
登录
它工作正常。
请确保example.html也位于登录html页面所在的路径中。另外,请检查是否存在@Andrew_CSE提到的弹出窗口阻止程序。当您单击“提交”按钮时,您的表单将被提交,浏览器将重新加载页面(因为您没有在表单中指定操作) 您需要防止提交viqjavascript(),或者将您提交的输入转换为带有类型按钮的按钮,以便单击它不会提交表单
var message=“右键单击禁用!”;
功能RTCLICK检查(keyp){
如果(navigator.appName==“Netscape”&&
keyp.which==3){
警报(信息);
返回false;
}
if(navigator.appVersion.indexOf(“MSIE”)!=-1&&event.button==2){
警报(信息);
返回false;
}
}
document.onmousedown=rtclickcheck;
功能检查(表格){
if(form.username.value==“admin”&&form.password.value==“123”){
window.open(“example.html”)
}否则{
log(“用户名或密码不匹配!”);
}
}
登录
按钮
表单提交会取消重定向,反之亦然。
请改用以下代码:
<html>
<head>
<title>Login</title>
<link rel="stylesheet" href="css/css1.css">
<script type="text/javascript">
var message = "Right Click Disabled!";
function rtclickcheck(keyp) {
if (navigator.appName == "Netscape" && keyp.which == 3) {
alert(message);
return false;
}
if (navigator.appVersion.indexOf("MSIE") != -1 && event.button == 2) {
alert(message); return false;
}
}
document.onmousedown = rtclickcheck;
function check(form)
{
if(form.username.value == "admin" && form.password.value == "123")
{
window.location.replace("example.html");
return false;
} else
{
alert("Username Or Password Doesn't Match!");
return false;
}
}
</script>
</head>
<body>
<div class="form-box">
<div class="head">LOGIN</div>
<div id="textbox">
<form onsubmit="return check(this);">
<input type="text" placeholder="Username" name="username">
<br>
<input type="password" placeholder="Password" name="password">
<br>
<input type="submit" name="btn_submit" value="Login">
</form>
</div>
</div>
</body>
</html>
登录
var message=“右键单击已禁用!”;
功能RTCLICK检查(keyp){
if(navigator.appName==“Netscape”&&keyp.which==3){
警报(信息);
返回false;
}
if(navigator.appVersion.indexOf(“MSIE”)!=-1&&event.button==2){
警告(消息);返回false;
}
}
document.onmousedown=rtclickcheck;
功能检查(表格)
{
if(form.username.value==“admin”&&form.password.value==“123”)
{
window.location.replace(“example.html”);
返回false;
}否则
{
警报(“用户名或密码不匹配!”);
返回false;
}
}
登录
您的代码虽然有点粗糙,但似乎运行正常。这里有一个重要的部分:--点击提交按钮确实会尝试在一个新窗口中打开“example.html”页面,假设您输入了“admin”用户名和“123”密码。如果选项卡/窗口未打开,您是否检查了弹出窗口阻止程序是否阻止了它?@SuperUser您应该提供一个。它无论如何都不起作用,但在在线网站上,它工作正常。你使用的代码与上面的完全相同吗?控制台中是否有任何错误?请尝试从控制台进行调试,也不要使用example.html,请尝试使用在线站点,如