13.07.2014

Jquery Redirection After Countdown

This article is about Javascript/Jquery redirection after countdown, which is 10 seconds in this example.

Our output will be like:

Javascript Redirection

Firstly, we need to Javascript redirection. When the following Javascript code block runs, we will be redirected to reitix.com (surely you can change the url).

window.location = "http://reitix.com";

Jquery Countdown

Secondly, wee need a javascript countdown algorithm. To solve this little problem, we will user setInterval method and trigger our update method at each interval (1 seconds) completes. Here we go:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(document).ready(function () {
var doUpdate = function () {
var i = parseInt($("#counter").html());
if (i !== 0) {
$("#counter").html(i - 1);
}
else
{
window.location = "http://reitix.com";
}
};
setInterval(doUpdate, 1000);
});
</script>

Further, if we want to update our html with each countdown:

<div>
You will be redirected after: 
<div id="counter">10</div> seconds
</div>

Done, with these codes, after 10 seconds, we will be redirected to reitix.com.

Jquery Redirection After Countdown
Bu makalenin telif hakkı ve tüm sorumlulukları yazara ait olup, şikayetler için lütfen bizimle iletişime geçiniz.
URL:
Etiketler:

Bu makale 2922 kez okundu

13.07.2014 tarihinde yazıldı
Reitix

Yorumlar

  • S_Operator
    25.10.2016

    404 hata sayfaları için yapılmasında fayda var, yoksa kullanıcı direk sayfayı kapatmayı tercih ediyor ve bir ziyaretçinizi kaybetmiş oluyorsunuz

  • lilith
    25.08.2016

    neden ingilizce olduğunu tek merak eden ben miyim?

  • chung
    09.06.2015

    ajax tarafından gerçekleştirilen işlemler için sunucuya iş bırakmadan yaptırmak gerekli olabiliyor, biraz daha görselleştirilebilir belki

Bu yazıya siz de yorum yapabilirsiniz

İnternet sitemizdeki deneyiminizi iyileştirmek için çerezler kullanıyoruz. Bu siteye giriş yaparak çerez kullanımını kabul etmiş sayılıyorsunuz. Daha fazla bilgi.