Ver Mensaje Individual
  #2 (permalink)  
Antiguo 25/05/2011, 07:44
Avatar de _cronos2
_cronos2
Colaborador
 
Fecha de Ingreso: junio-2010
Mensajes: 2.062
Antigüedad: 13 años, 10 meses
Puntos: 310
Respuesta: Redireccionar con cuenta regresiva y con opcion de detener la redireccion

A ver:
Código Javascript:
Ver original
  1. var contador = function(tiempo, intervalo){
  2.  var enCurso = 0, intv = intervalo || 1000;
  3.  var veces = tiempo / intv, este = this, timer;
  4.  this.empezar = function(callback){
  5.   enCurso = 1;
  6.   timer = setTimeout(function(){
  7.    if(veces + 1 && enCurso){
  8.     callback(veces-- * intv);
  9.     setTimeout(function(){ este.empezar(callback); }, intv);
  10.    }else{
  11.     return enCurso = 0;
  12.    }
  13.   }, intv);
  14.  };
  15.  this.parar = function(){
  16.   if(enCurso){ enCurso = 0; }
  17.  };
  18. }
  19. var cuentaAtras = new contador(10000);
  20. document.body.onload = function(){ cuentaAtras.empezar(function(tiempo){
  21.  document.getElementById('cuenta').innerHTML = 'Quedan ' + tiempo / 1000 + ' segundos';
  22.  if(!tiempo){ location.href = 'otrapagina.php'; }
  23. }); }
  24. document.getElementById('boton-parar').onclick = cuentaAtras.parar;
Saludos (:
__________________
" Getting older’s not been on my plans
but it’s never late, it’s never late enough for me to stay. "
Cigarettes - Russian Red