Redirect with countdown timer
Countdown timer for redirecting to another URL after several seconds
by ffabreti
HTML
<HTML>
<HEAD>
<meta charset="utf-8">
<style>
body {background-color: powderblue; font-family: 'tahoma';}
p { font-size: 24px; }
img#logo {height: auto; max-width: 100%; }
</style>
</HEAD>
<body>
<p></p>
<img alt='' id='logo' src=''/>
<h2> Este endereço mudou para <a id='newlink' href='#'><p class='url'></p></a></h2>
<p> Este endereço antigo ficará disponível por alguns dias para que você possa acostumar-se a utilizar o novo endereço. </p>
Redirecionado em <span id="seconds">..</span> segundos.
</body>
<script>
// Countdown timer for redirecting to another URL after several seconds
var seconds = 20; // seconds for HTML
var foo; // variable for clearInterval() function
var url=' https://autodiagnostico-hom.trabalho.gov.br';
function redirect() {
document.location.href = url;
}
function updateSecs() {
document.getElementById("seconds").innerHTML = seconds;
seconds--;
if (seconds == -1) {
clearInterval(foo);
redirect();
}
}
function countdownTimer() {
foo = setInterval(function () {
updateSecs()
}, 1000);
}
//----- MAIN ------
updateSecs();
document.getElementById('newlink').href = url;
document.getElementById('newlink').innerHTML = url;
countdownTimer();
...