How to add delay before redirecting to another page

<script>
function checkPassword(){
var password = document.getElementById("logginpasswordinput").value;
var message = document.getElementById("message");

if(password == "Test"){
message.textContent = "Password correct. Redirecting...";
message.className = "message success";


window.location.href="/dashboard";

}else{
message.textContent = "Password Incorrect!! . Try again.";
message.className = "message error";
}
}

</script>
<script>
function checkPassword(){
var password = document.getElementById("logginpasswordinput").value;
var message = document.getElementById("message");

if(password == "Test"){
message.textContent = "Password correct. Redirecting...";
message.className = "message success";


window.location.href="/dashboard";

}else{
message.textContent = "Password Incorrect!! . Try again.";
message.className = "message error";
}
}

</script>
No description
20 Replies
Cosmic
Cosmic2mo ago
Me nub in javascript , das why ;-;
Pi, a future fluent jp speaker
You can use a setTimeout() function I guess
Cosmic
Cosmic2mo ago
Lemme check
13eck
13eck2mo ago
So…again, what are you trying to accomplish? Where do you want a dely? Why do you want the delay?
Pi, a future fluent jp speaker
Maybe he wants a delay before the user going to the next page. Like to make a loading screen or show some message
13eck
13eck2mo ago
Maybe, but we don't know yet. Which is my point :p
Chris Bolson
Chris Bolson2mo ago
To be fair in the title Cosmic does say "...delay before redirecting to another page"
Cosmic
Cosmic2mo ago
While redirecting to new page some time , my esp8266 shows no page found.. so just making sure if adding delay before redirecting would help
13eck
13eck2mo ago
Adding a delay won't help if there's no page to redirect to
Pi, a future fluent jp speaker
A point which I would like to point out, instead of using className you would like to use classList.add("name-of-the-class"), because className = … can overwrite the other classes iirc
Cosmic
Cosmic2mo ago
But sometimes when i take that page directly , it loads.. When i go through the login html , it says no page found..
13eck
13eck2mo ago
A few things: 1. You're using an invalid URL in your "redirect" (it needs to be a fully qualified URL) 1. You should be using window.location.assign(URL) https://developer.mozilla.org/en-US/docs/Web/API/Location/assign Or you could use window.location.pathname instead, I guess, as that changes only the pathname. But I believe you're supposed to use the methods instead of setting the location bits individually
Cosmic
Cosmic2mo ago
idk what it means 💀 , Im using html for first time just for a proj. so , href and assign(URL) works the same way?
13eck
13eck2mo ago
No, they're different. That's why I suggest you use .assign() instead instead of window.location.href="/dashboard"; you should do window.location.assign("/dashboard");. See if that works
Cosmic
Cosmic2mo ago
Assign , adds a part to url or removes it??
13eck
13eck2mo ago
The assign() method of the Location interface causes the window to load and display the document at the URL specified. After the navigation occurs, the user can navigate back to the page that called Location.assign() by pressing the "back" button.
MDN It's a way of changing the URL to a different one. You can either do a full URL (https://discord.com/developers) or a relative path (/developers)
Cosmic
Cosmic2mo ago
like if it was, http://test.local/ , applying href="/dashboard" it will become http://test.local/dashboard
And assign will go back to url right? (shortening it , basically what i mean)
No description
13eck
13eck2mo ago
Yes
Cosmic
Cosmic2mo ago
I was also looking for that thing.. thanks for the info , might be useful for future :) So here , basically , ESP8266 chip checks for if there is any changes to url. when login is sucessfull . It will check is they added.. And execute the void mainpage() {}
No description
Cosmic
Cosmic2mo ago
I suck in explaining 💀
Want results from more Discord servers?
Add your server