我有一个登录表单,但是当它成功登录时,它不会重定向到我想要的页面。我希望它重定向到一个名为 PF1.1.html 的 html 页面,但在示例中我将地址提供给了 google,但它仍然不起作用。除了重定向部分之外,javascript 可以正常工作,我不知道为什么我尝试使用 replace 而不是 href,但仍然无法正常工作
var attempt = 3; // Variable to count number of attempts.
// Below function Executes on click of login button.
function validate(){
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;
if ( username == "teste" && password == "teste"){
alert ("Login successfully");
window.location.href = "https://www.google.com/webhp?ie=UTF-8&rct=j"; // Redirecting to other page.
return false;
}
else{
attempt --;// Decrementing by one.
alert("You have left "+attempt+" attempt;");
// Disabling fields after 3 attempts.
if( attempt == 0){
document.getElementById("username").disabled = true;
document.getElementById("password").disabled = true;
document.getElementById("submit").disabled = true;
return false;
}
}
}
/*******************************************LOGIN********************************/
html, body {
width: 3779.527559055px;
height: 100%;
font-family: "Helvetica Neue", Helvetica, sans-serif;
color: #444;
-webkit-font-smoothing: antialiased;
background-color: #111;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
zoom{
zoom: 25%;
}
/*******************************************SHUTDOWN BUTTON********************************/
#btn1{
background-color: Transparent;
background-repeat:no-repeat;
border: none;
cursor:pointer;
overflow: hidden;
}
button img{
width: 400px;
height: 400px;
}
/*********************************************LOGIN***************************************/
@import url(https://fonts.googleapis.com/css?family=Audiowide);
::-moz-selection {
background: #cc0000;
text-shadow: none;
}
::selection {
background: #cc0000;
text-shadow: none;
}
html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td,article,aside,canvas,details,embed,figure,figcaption,footer,header,hgroup,menu,nav,output,ruby,section,summary,time,mark,audio,video {
border: 0;
font: inherit;
font-size: 100%;
margin: 0;
padding: 0;
vertical-align: baseline;
text-rendering: optimizeLegibility;
}
article,aside,details,figcaption,figure,footer,header,hgroup,menu,nav,section {
display: block;
}
html,body {
height: 100%;
margin: 0;
padding: 0;
}
body {
color: #FFF;
font-family: "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif;
font-size: 12px;
line-height: 1;
}
.background-wrap {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
z-index: -1;
overflow: hidden;
}
* {
box-sizing: border-box;
cursor: default;
outline: none;
}
form {
background: #111;
border-radius: .4em;
bottom: 0;
box-shadow: 0 5px 10px 5px rgba(0,0,0,0.2);
height: 1000px;
left: 0;
margin: auto;
overflow: hidden;
position: absolute;
right: 0;
top: 0;
width: 1500px;
}
form:after {
background: linear-gradient(to right, #111111, #444444, #b6b6b8, #444444, #2F2F2F, #272727);
content: "";
display: block;
height: 1px;
left: 50px;
position: absolute;
top: 0;
width: 150px;
}
form:before {
border-radius: 50%;
box-shadow: 0 0 6px 4px #fff;
content: "";
display: block;
height: 5px;
left: 34%;
position: absolute;
top: -7px;
width: 8px;
}
.inset {
border-top: 1px solid #19191a;
padding: 20px;
}
form h1 {
font-family: 'Audiowide';
border-bottom: 1px solid #000;
font-size: 200px;
padding: 15px 0;
position: relative;
text-align: center;
text-shadow: 0 1px 0 #000;
}
form h1 {
color: #FFbb00;
font-family: Audiowide;
font-weight: normal;
}
form h1.poweron {
color: #ffffff;
transition: all 0.5s;
animation: flicker 1s ease-in-out 1 alternate, neon 1.5s ease-in-out infinite alternate;
animation-delay: 0s, 1s;
}
form h1:after {
position: absolute;
width: 250px;
height: 180px;
content: "";
display: block;
pointer-events: none;
top: 0;
margin-left: 138px;
transform-style: flat;
transform: skew(20deg);
background: -moz-linear-gradient(top, hsla(0,0%,100%,0.1) 0%, hsla(0,0%,100%,0) 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,hsla(0,0%,100%,0.2)), color-stop(100%,hsla(0,0%,100%,0)));
background: -webkit-linear-gradient(top, hsla(0,0%,100%,0.1) 0%,hsla(0,0%,100%,0) 100%);
background: -o-linear-gradient(top, hsla(0,0%,100%,0.1) 0%,hsla(0,0%,100%,0) 100%);
background: -ms-linear-gradient(top, hsla(0,0%,100%,0.1) 0%,hsla(0,0%,100%,0) 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#42ffffff', endColorstr='#00ffffff',GradientType=0 );
background: linear-gradient(to bottom, hsla(0,0%,100%,0.1) 0%,hsla(0,0%,100%,0) 100%);
}
input[type=username], input[type=password] {
background: linear-gradient(#1f2124,#27292c);
border: 1px solid #222;
border-radius: .3em;
box-shadow: 0 1px 0 rgba(255,255,255,0.1);
color: #FFF;
font-size: 150px;
margin-bottom: 20px;
padding: 20px 10px;
width: 100%;
}
input[type=username]:disabled, input[type=password]:disabled {
color: #999;
}
.p-container {
padding: 0 20px 20px;
}
.p-container:after {
clear: both;
content: "";
display: table;
}
.p-container span {
color: #0d93ff;
display: block;
float: left;
padding-top: 8px;
}
input[type=submit] {
background: #fb0;
border: 1px solid rgba(0,0,0,0.4);
border-radius: .3em;
box-shadow: inset 0 1px 0 rgba(255,255,255,0.3), inset 0 10px 10px rgba(255,255,255,0.1);
color: #873C00;
cursor: pointer;
font-size: 120px;
font-weight: bold;
height: 200px;
padding: 10px 10px;
width: 100%;
}
.denied {
color: white !important;
text-shadow: 0 0 1px black;
background: #EE0000 !important;
}
input[type=submit]:hover, input[type=submit]:focus {
box-shadow: inset 0 1px 0 rgba(255,255,255,0.3), inset 0 -10px 10px rgba(255,255,255,0.1);
}
input[type=text]:hover:not([disabled]),
input[type=text]:focus,
input[type=password]:hover:not([disabled]),
input[type=password]:focus,
label:hover ~ input[type=text],
label:hover ~ input[type=password] {
background: #27292c;
}
@keyframes neon {
from {
text-shadow:
0 0 2.5px #fff,
0 0 5px #fff,
0 0 7.5px #fff,
0 0 10px #B6FF00,
0 0 17.5px #B6FF00,
0 0 20px #B6FF00,
0 0 25px #B6FF00,
0 0 37.5px #B6FF00;
}
to {
text-shadow:
0 0 3px #fff,
0 0 7px #fff,
0 0 13px #fff,
0 0 17px #B6FF00,
0 0 33px #B6FF00,
0 0 38px #B6FF00,
0 0 48px #B6FF00,
0 0 63px #B6FF00;
}
}
@keyframes flicker {
0% {
text-shadow:
0 0 2.5px #fff,
0 0 5px #fff,
0 0 7.5px #fff,
0 0 10px #B6FF00,
0 0 17.5px #B6FF00,
0 0 20px #B6FF00,
0 0 25px #B6FF00,
0 0 37.5px #B6FF00;
}
2% {
text-shadow: none;
}
8% {
text-shadow:
0 0 2.5px #fff,
0 0 5px #fff,
0 0 7.5px #fff,
0 0 10px #B6FF00,
0 0 17.5px #B6FF00,
0 0 20px #B6FF00,
0 0 25px #B6FF00,
0 0 37.5px #B6FF00;
}
10% {
text-shadow: none;
}
20% {
text-shadow:
0 0 2.5px #fff,
0 0 5px #fff,
0 0 7.5px #fff,
0 0 10px #B6FF00,
0 0 17.5px #B6FF00,
0 0 20px #B6FF00,
0 0 25px #B6FF00,
0 0 37.5px #B6FF00;
}
22% {
text-shadow: none;
}
24% {
text-shadow:
0 0 2.5px #fff,
0 0 5px #fff,
0 0 7.5px #fff,
0 0 10px #B6FF00,
0 0 17.5px #B6FF00,
0 0 20px #B6FF00,
0 0 25px #B6FF00,
0 0 37.5px #B6FF00;
}
28% {
text-shadow: none;
}
32% {
text-shadow:
0 0 2.5px #fff,
0 0 5px #fff,
0 0 7.5px #fff,
0 0 10px #B6FF00,
0 0 17.5px #B6FF00,
0 0 20px #B6FF00,
0 0 25px #B6FF00,
0 0 37.5px #B6FF00;
}
34% {
text-shadow: none;
}
36% {
text-shadow: none;
}
42% {
text-shadow: none;
}
100% {
text-shadow:
0 0 2.5px #fff,
0 0 5px #fff,
0 0 7.5px #fff,
0 0 10px #B6FF00,
0 0 17.5px #B6FF00,
0 0 20px #B6FF00,
0 0 25px #B6FF00,
0 0 37.5px #B6FF00;
}
}
<!DOCTYPE html>
<html>
<head>
<title>Desk+ - Grupo 36</title>
<link rel="stylesheet" type="text/css" href="PF1.css">
</head>
<body>
<div id="Locked Screen">
<div id="Login">
<div class="background-wrap">
<div class="background"></div>
</div>
<form id="accesspanel">
<h1 id="litheader">Desk+</h1>
<div class="inset">
<p>
<input id="username" type="username" size="64" maxLength="64"
placeholder=Username(teste)>
</p>
<p>
<input type="password" name="password" id="password" placeholder="Password(teste)" required>
</p>
<div style="text-align: center;">
</div>
<p class="p-container">
<input onclick="validate()" type="submit" id="go" value="Login">
</p>
</form>
</div>
<datalist id="users">
<option value="teste">
</datalist>
<div id="Logout">
<!---<a href="logout.php" id="LogoutAction"><img src="https://cdn2.iconfinder.com/data/icons/crystalproject/crystal_project_256x256/apps/exit.png"></a>--->
<button type="submit" id="btn1"><img src= "https://cdn2.iconfinder.com/data/icons/crystalproject/crystal_project_256x256/apps/exit.png"/></button>
</div>
</div>
</body>
</html>
顺便把它全屏,缩小到25%
最佳答案
通过将 type='submit'
切换为 type='button'
我能够使重定向正常工作。
当点击一个submit
按钮,然后打开一个alert
时,浏览器会等待alert 关闭以提交表单。所以它在重定向和返回 false 可以被处理之前提交表单。
由于浏览器的限制,重定向在片段中不起作用,但它确实有效。
var attempt = 3; // Variable to count number of attempts.
// Below function Executes on click of login button.
function validate(){
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;
if ( username == "teste" && password == "teste"){
alert ("Login successfully");
window.location.href = "https://www.google.com/webhp?ie=UTF-8&rct=j"; // Redirecting to other page.
return false;
}
else{
attempt --;// Decrementing by one.
alert("You have left "+attempt+" attempt;");
// Disabling fields after 3 attempts.
if( attempt == 0){
document.getElementById("username").disabled = true;
document.getElementById("password").disabled = true;
document.getElementById("submit").disabled = true;
return false;
}
}
}
/*******************************************LOGIN********************************/
html, body {
width: 3779.527559055px;
height: 100%;
font-family: "Helvetica Neue", Helvetica, sans-serif;
color: #444;
-webkit-font-smoothing: antialiased;
background-color: #111;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
zoom{
zoom: 25%;
}
/*******************************************SHUTDOWN BUTTON********************************/
#btn1{
background-color: Transparent;
background-repeat:no-repeat;
border: none;
cursor:pointer;
overflow: hidden;
}
button img{
width: 400px;
height: 400px;
}
/*********************************************LOGIN***************************************/
@import url(https://fonts.googleapis.com/css?family=Audiowide);
::-moz-selection {
background: #cc0000;
text-shadow: none;
}
::selection {
background: #cc0000;
text-shadow: none;
}
html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td,article,aside,canvas,details,embed,figure,figcaption,footer,header,hgroup,menu,nav,output,ruby,section,summary,time,mark,audio,video {
border: 0;
font: inherit;
font-size: 100%;
margin: 0;
padding: 0;
vertical-align: baseline;
text-rendering: optimizeLegibility;
}
article,aside,details,figcaption,figure,footer,header,hgroup,menu,nav,section {
display: block;
}
html,body {
height: 100%;
margin: 0;
padding: 0;
}
body {
color: #FFF;
font-family: "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif;
font-size: 12px;
line-height: 1;
}
.background-wrap {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
z-index: -1;
overflow: hidden;
}
* {
box-sizing: border-box;
cursor: default;
outline: none;
}
form {
background: #111;
border-radius: .4em;
bottom: 0;
box-shadow: 0 5px 10px 5px rgba(0,0,0,0.2);
height: 1000px;
left: 0;
margin: auto;
overflow: hidden;
position: absolute;
right: 0;
top: 0;
width: 1500px;
}
form:after {
background: linear-gradient(to right, #111111, #444444, #b6b6b8, #444444, #2F2F2F, #272727);
content: "";
display: block;
height: 1px;
left: 50px;
position: absolute;
top: 0;
width: 150px;
}
form:before {
border-radius: 50%;
box-shadow: 0 0 6px 4px #fff;
content: "";
display: block;
height: 5px;
left: 34%;
position: absolute;
top: -7px;
width: 8px;
}
.inset {
border-top: 1px solid #19191a;
padding: 20px;
}
form h1 {
font-family: 'Audiowide';
border-bottom: 1px solid #000;
font-size: 200px;
padding: 15px 0;
position: relative;
text-align: center;
text-shadow: 0 1px 0 #000;
}
form h1 {
color: #FFbb00;
font-family: Audiowide;
font-weight: normal;
}
form h1.poweron {
color: #ffffff;
transition: all 0.5s;
animation: flicker 1s ease-in-out 1 alternate, neon 1.5s ease-in-out infinite alternate;
animation-delay: 0s, 1s;
}
form h1:after {
position: absolute;
width: 250px;
height: 180px;
content: "";
display: block;
pointer-events: none;
top: 0;
margin-left: 138px;
transform-style: flat;
transform: skew(20deg);
background: -moz-linear-gradient(top, hsla(0,0%,100%,0.1) 0%, hsla(0,0%,100%,0) 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,hsla(0,0%,100%,0.2)), color-stop(100%,hsla(0,0%,100%,0)));
background: -webkit-linear-gradient(top, hsla(0,0%,100%,0.1) 0%,hsla(0,0%,100%,0) 100%);
background: -o-linear-gradient(top, hsla(0,0%,100%,0.1) 0%,hsla(0,0%,100%,0) 100%);
background: -ms-linear-gradient(top, hsla(0,0%,100%,0.1) 0%,hsla(0,0%,100%,0) 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#42ffffff', endColorstr='#00ffffff',GradientType=0 );
background: linear-gradient(to bottom, hsla(0,0%,100%,0.1) 0%,hsla(0,0%,100%,0) 100%);
}
input[type=username], input[type=password] {
background: linear-gradient(#1f2124,#27292c);
border: 1px solid #222;
border-radius: .3em;
box-shadow: 0 1px 0 rgba(255,255,255,0.1);
color: #FFF;
font-size: 150px;
margin-bottom: 20px;
padding: 20px 10px;
width: 100%;
}
input[type=username]:disabled, input[type=password]:disabled {
color: #999;
}
.p-container {
padding: 0 20px 20px;
}
.p-container:after {
clear: both;
content: "";
display: table;
}
.p-container span {
color: #0d93ff;
display: block;
float: left;
padding-top: 8px;
}
input[type=submit] {
background: #fb0;
border: 1px solid rgba(0,0,0,0.4);
border-radius: .3em;
box-shadow: inset 0 1px 0 rgba(255,255,255,0.3), inset 0 10px 10px rgba(255,255,255,0.1);
color: #873C00;
cursor: pointer;
font-size: 120px;
font-weight: bold;
height: 200px;
padding: 10px 10px;
width: 100%;
}
.denied {
color: white !important;
text-shadow: 0 0 1px black;
background: #EE0000 !important;
}
input[type=submit]:hover, input[type=submit]:focus {
box-shadow: inset 0 1px 0 rgba(255,255,255,0.3), inset 0 -10px 10px rgba(255,255,255,0.1);
}
input[type=text]:hover:not([disabled]),
input[type=text]:focus,
input[type=password]:hover:not([disabled]),
input[type=password]:focus,
label:hover ~ input[type=text],
label:hover ~ input[type=password] {
background: #27292c;
}
@keyframes neon {
from {
text-shadow:
0 0 2.5px #fff,
0 0 5px #fff,
0 0 7.5px #fff,
0 0 10px #B6FF00,
0 0 17.5px #B6FF00,
0 0 20px #B6FF00,
0 0 25px #B6FF00,
0 0 37.5px #B6FF00;
}
to {
text-shadow:
0 0 3px #fff,
0 0 7px #fff,
0 0 13px #fff,
0 0 17px #B6FF00,
0 0 33px #B6FF00,
0 0 38px #B6FF00,
0 0 48px #B6FF00,
0 0 63px #B6FF00;
}
}
@keyframes flicker {
0% {
text-shadow:
0 0 2.5px #fff,
0 0 5px #fff,
0 0 7.5px #fff,
0 0 10px #B6FF00,
0 0 17.5px #B6FF00,
0 0 20px #B6FF00,
0 0 25px #B6FF00,
0 0 37.5px #B6FF00;
}
2% {
text-shadow: none;
}
8% {
text-shadow:
0 0 2.5px #fff,
0 0 5px #fff,
0 0 7.5px #fff,
0 0 10px #B6FF00,
0 0 17.5px #B6FF00,
0 0 20px #B6FF00,
0 0 25px #B6FF00,
0 0 37.5px #B6FF00;
}
10% {
text-shadow: none;
}
20% {
text-shadow:
0 0 2.5px #fff,
0 0 5px #fff,
0 0 7.5px #fff,
0 0 10px #B6FF00,
0 0 17.5px #B6FF00,
0 0 20px #B6FF00,
0 0 25px #B6FF00,
0 0 37.5px #B6FF00;
}
22% {
text-shadow: none;
}
24% {
text-shadow:
0 0 2.5px #fff,
0 0 5px #fff,
0 0 7.5px #fff,
0 0 10px #B6FF00,
0 0 17.5px #B6FF00,
0 0 20px #B6FF00,
0 0 25px #B6FF00,
0 0 37.5px #B6FF00;
}
28% {
text-shadow: none;
}
32% {
text-shadow:
0 0 2.5px #fff,
0 0 5px #fff,
0 0 7.5px #fff,
0 0 10px #B6FF00,
0 0 17.5px #B6FF00,
0 0 20px #B6FF00,
0 0 25px #B6FF00,
0 0 37.5px #B6FF00;
}
34% {
text-shadow: none;
}
36% {
text-shadow: none;
}
42% {
text-shadow: none;
}
100% {
text-shadow:
0 0 2.5px #fff,
0 0 5px #fff,
0 0 7.5px #fff,
0 0 10px #B6FF00,
0 0 17.5px #B6FF00,
0 0 20px #B6FF00,
0 0 25px #B6FF00,
0 0 37.5px #B6FF00;
}
}
<!DOCTYPE html>
<html>
<head>
<title>Desk+ - Grupo 36</title>
<link rel="stylesheet" type="text/css" href="PF1.css">
</head>
<body>
<div id="Locked Screen">
<div id="Login">
<div class="background-wrap">
<div class="background"></div>
</div>
<form id="accesspanel">
<h1 id="litheader">Desk+</h1>
<div class="inset">
<p>
<input id="username" type="username" size="64" maxLength="64"
placeholder=Username(teste)>
</p>
<p>
<input type="password" name="password" id="password" placeholder="Password(teste)" required>
</p>
<div style="text-align: center;">
</div>
<p class="p-container">
<input onclick="validate()" type="button" id="go" value="Login">
</p>
</form>
</div>
<datalist id="users">
<option value="teste">
</datalist>
<div id="Logout">
<!---<a href="logout.php" id="LogoutAction"><img src="https://cdn2.iconfinder.com/data/icons/crystalproject/crystal_project_256x256/apps/exit.png"></a>--->
<button type="submit" id="btn1"><img src= "https://cdn2.iconfinder.com/data/icons/crystalproject/crystal_project_256x256/apps/exit.png"/></button>
</div>
</div>
</body>
</html>
关于javascript - 登录表单在登录后不重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55937849/