Sometime during our front-end development, we may wish to have a redirect that pauses for few seconds with a countdown (threee, twoo, onee….), before sending the visitor off to the destination. Something like starting a 100-meter race 😉
The use-case is where you want to show an important message/text/banner to the visitor before proceeding the redirect. Adly and many other URL shortening services use this for revenue.
Ok, let’s get to the programming side now. The complete code for a simple example is given below.
All we do here is,
setTimeoutfunction to reduce remaining seconds after each second
window.locationmethod after remaining time cross 0.
That’s all folks 🙂 I really appreciate it when you leave a comment below. Keep coding.