<button onclick="redirect()">Перенаправление через 5 секунд</button>
<script>
function redirect() {
setTimeout(function() {
window.location.href = "http://example.com";
}, 5000);
}
</script>
<button onclick="redirect()">Перенаправление через 5 секунд</button>
<script>
function redirect() {
setTimeout(function() {
window.location.href = "http://example.com";
}, 5000);
}
</script>
function redirect() {
var seconds = 5;
var countdown = document.getElementById("output");
var interval = setInterval(function () {
countdown.innerHTML = "Переадресация на другую страницу через " + seconds + " секунд";
seconds--;
if (seconds < 0) {
clearInterval(interval);
window.location.href = "https://example.com";
}
}, 1000);
}
<b><span id="time"></span></b>
02
<script type="text/javascript">
var i = 15;//время в сек.
function time(){
document.getElementById("time").innerHTML = i;//визуальный счетчик
i--;//уменьшение счетчика
if (i < 0) location.href = "http://javascript.ru";//редирект
}
time();
setInterval(time, 1000);
</script>