user3686754
user3686754

Reputation: 11

run a function after 60 seconds of user being on website not on a single page

We are trying to make a load a JQuery function 60 seconds after the user has landed on the website.

We can do this per page but cannot do this for the who visit. e.g. the user could browse 4 pages within 60 seconds and then it would load...

Our code for page load is :

$(window).load(function(){

  setTimeout(function() {
       loadPopup();
  }, 500);
})

How can we acheive this for the website visit and not per page?

Upvotes: 1

Views: 200

Answers (1)

hsz
hsz

Reputation: 152284

Just try with:

var time = $.cookie('time') || 0;    
if (time < 60) {
    var interval = setInterval(function(){
        if (time >= 60) {
            console.log('over 60 seconds!');
            clearInterval(interval);
        } else {
            $.cookie('time', ++time);
        }
    }, 1000);
}

It uses jQuery Cookie library.

To reset counter just add time = 0 in the if clause.

Demo

Upvotes: 2

Related Questions