A Pen by Konstantinos Krevatas on CodePen.
Created
March 4, 2023 00:56
-
-
Save smartexpert/768833fb2277cc3da3b968dc2c8a71d9 to your computer and use it in GitHub Desktop.
Redirect counter with message
This file contains hidden or 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
<center> | |
<br/> | |
<h1>Announcement</h1> | |
<p>You will be redirected in <span id="seconds-holder"></span> seconds.<br/><br/> If your browser does not redirect you automatically click <a href="" id="link">here</a>. | |
</p> | |
</center> |
This file contains hidden or 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
class countdownTimer { | |
constructor(elementId, seconds, redirectUrl) { | |
this._newUrl = redirectUrl; | |
this._intvl = null; | |
this._selector = elementId; | |
this._seconds = seconds; | |
document.getElementById("link").href = this._newUrl; | |
this.start(); | |
} | |
start() { | |
var _this = this; | |
_this.updateSecs(); | |
this._intvl = setInterval(function() { | |
_this.updateSecs(); | |
}, 1000); | |
} | |
updateSecs() { | |
document.getElementById(this._selector).innerHTML = this._seconds; | |
this._seconds--; | |
if (this._seconds == -1) { | |
clearInterval(this._intvl); | |
this.redirect(); | |
} | |
} | |
redirect() { | |
document.location.href = this._newUrl; | |
} | |
} | |
//And now invoke | |
var co = new countdownTimer("seconds-holder", 45, 'http://kostas.krevatas.net'); |
This file contains hidden or 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
* { | |
font-family: "Open Sans", sans-serif; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment