在下面的代码中,"location. replace(" ./mc.html ")"只在我重新加载页面后生效,我该如何修复这个问题?
编辑:对不起,它把所有的代码在一行+这是我的第一个职位,我不知道关于(')x3之前/之后的代码
<!DOCTYPE html>
<html>
<head>
<style>
/* CSS for the main page */
#main-page {
display: none;
}
/* CSS for the passcode input form */
#passcode-form {
display: none;
}
/* CSS for the 404 page */
#404-page {
display: none;
}
</style>
</head>
<body>
<div id="main-page">
</div>
<div id="passcode-form">
<form>
<label for="passcode">Enter passcode:
</label>
<input type="text" id="passcode-input" name="passcode">
<button type="button" id="submit-passcode">Submit
</button>
</form>
</div>
<div id="404-page">
<div title="404">404
</div>
<style> @import url('https://fonts.googleapis.com/css?family=Fira+Mono:400');
body{
display: flex;
width: 100vw;
height: 100vh;
align-items: center;
justify-content: center;
margin: 0;
background: #131313;
color: #fff;
font-size: 96px;
font-family: 'Fira Mono', monospace;
letter-spacing: -7px;
}
div{
animation: glitch 1s linear infinite;
}
@keyframes glitch{
2%,64%{
transform: translate(2px,0) skew(0deg);
}
4%,60%{
transform: translate(-2px,0) skew(0deg);
}
62%{
transform: translate(0,0) skew(5deg);
}
}
div:before, div:after{
content: attr(title);
position: absolute;
left: 0;
}
div:before{
animation: glitchTop 1s linear infinite;
clip-path: polygon(0 0, 100% 0, 100% 33%, 0 33%);
-webkit-clip-path: polygon(0 0, 100% 0, 100% 33%, 0 33%);
}
@keyframes glitchTop{
2%,64%{
transform: translate(2px,-2px);
}
4%,60%{
transform: translate(-2px,2px);
}
62%{
transform: translate(13px,-1px) skew(-13deg);
}
}
div:after{
animation: glitchBotom 1.5s linear infinite;
clip-path: polygon(0 67%, 100% 67%, 100% 100%, 0 100%);
-webkit-clip-path: polygon(0 67%, 100% 67%, 100% 100%, 0 100%);
}
@keyframes glitchBotom{
2%,64%{
transform: translate(-2px,0);
}
4%,60%{
transform: translate(-2px,0);
}
62%{
transform: translate(-22px,5px) skew(21deg);
}
}
</style>
</div>
<script> // Get the current URL var currentUrl = window.location.href; // Check if the current URL contains "?the_passcode" if (currentUrl.indexOf("?the_passcode") !== -1) { // Check if the passcode is stored in local storage var passcode = localStorage.getItem("passcode"); if (passcode === "711iscool") { // Show the main page document.getElementById("main-page").style.display = "block"; document.getElementById("passcode-form").style.display = "none"; location.replace("./mc.html") } else { // Show the passcode input form document.getElementById("passcode-form").style.display = "block"; document.getElementById("404-page").style.display = "none"; // Add an event listener to the submit button document.getElementById("submit-passcode").addEventListener("click", function() { // Get the value of the passcode input var inputPasscode = document.getElementById("passcode-input").value; // Check if the input passcode is equal to "711iscool" if (inputPasscode === "711iscool") { // Store the passcode in local storage localStorage.setItem("passcode", inputPasscode); // Show the main page document.getElementById("main-page").style.display = "block"; document.getElementById("passcode-form").style.display = "none"; } else { // Show an error message alert("Incorrect passcode. Please try again."); } }); } } else { document.getElementById("404-page").style.display = "block"; setTimeout(function() { window.location.href = "https://www.youtube.com/@TechGeekUnited"; }, 10000); } </script>
</body>
</html>
应该发生什么:当输入正确的密码时,它将重定向到[当前URL ]/mc. html。
1条答案
按热度按时间mwngjboj1#
一个表单元素总是发送回一个请求到服务器作为默认(POST或GET),我可以看到你尝试使用javascript来重定向。它不会工作,因为它只运行在客户端(网页浏览器)。你也不应该使用javascript来管理登录,因为它是不安全的。尝试学习一些关于表单处理的更多内容。