Domanda

Pensavo che sarebbe stato facile, ma sembra che sia troppo breve o troppo lungo.

Sto cercando di far disconnettere l'utente dopo 3 minuti questo è il conto alla rovescia che pensavo avrebbe funzionato Ho provato 3000, 300, 3 * 60, 3 * 1000 e così via

var timeout = 30*1800;

Questa è la funzione che sto cercando di eseguire,

    function loadidle(){

          var timeout = 180000;
          //alert(timeout);

          $(document).bind("idle.idleTimer", function(){

              logout();

          });


          $.idleTimer(timeout);
}
È stato utile?

Soluzione

Hai solo bisogno di un semplice timer.Esistono molte varietà.Ecco un esempio a buon mercato che lo astrae bene come classe.Puoi "continuare" il timer chiamando .reset ().

function Timeout(seconds, callback){
    this.length = seconds * 1000;
    this.callback = callback;
    this.start();
}
Timeout.prototype = {
    start: function(){
        var self = this;
        this.stop();
        this.timer = setTimeout(function(){
            self.complete();
        },this.length);
    },
    stop: function(){
        if (this.timer) clearTimeout(this.timer);
        this.timer = null;
    },
    complete: function(){
        if (this.callback) this.callback();
        this.stop();
    },
    reset: function() {
        this.stop();
        this.start();
    }
}

Avvia un nuovo timer:

var timer = new Timeout(3 * 60, logout);
timer.reset(); // refresh the timer
timer.stop(); // cancel the timer

Altri suggerimenti

Sono abbastanza sicuro che JS (e quindi jQuery) utilizzino i millisecondi, quindi ti serviranno 3 * 60 * 1000.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top