Reputation: 11
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
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.
Upvotes: 2