Last active
September 19, 2022 05:30
-
-
Save Joel-James/62d98e8cb3a1b6b05102 to your computer and use it in GitHub Desktop.
Count Down Redirect Uisng JavaScript - https://duckdev.com/blog/count-down-redirect-using-javascript/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Modify this according to your requirement --> | |
<h3> | |
Redirecting to duckdev.com after <span id="countdown">10</span> seconds | |
</h3> | |
<!-- JavaScript part --> | |
<script type="text/javascript"> | |
// Total seconds to wait | |
var seconds = 10; | |
function countdown() { | |
seconds = seconds - 1; | |
if (seconds < 0) { | |
// Chnage your redirection link here | |
window.location = "https://duckdev.com"; | |
} else { | |
// Update remaining seconds | |
document.getElementById("countdown").innerHTML = seconds; | |
// Count down using javascript | |
window.setTimeout("countdown()", 1000); | |
} | |
} | |
// Run countdown function | |
countdown(); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I just wanted to say thank you! I went ahead and made some modifications that suite my needs and thought I'd share them here. I kept my HTML intact just to show a fully working code layout for reference. The script will now get all its variables from the HTML directly so you don't have to update your code in multiple sections when implementing for another project.
Enjoy!
-- The Dude