Reputation: 315
I looking to adv code like this page do : vozforums.com
They open a overlay pop-up every 15 minutes, use cookie. Here is screen shot :
I'm look in to they code and they using this pop-up code : http://defunkt.io/facebox/
But i'm do not know how to open pop-up every 15 minutes and just one-time per session (use jquery and cookie). So please help.
Upvotes: 0
Views: 2903
Reputation: 3143
A cookie can be set for a certain amount of time. You just need to check if the cookie exists, you shouldn't show the popup else show it and set the cookie.
if(readCookie('popupshown') == null)
{
//show popup
}
methods for reading and setting cookies:
// Cookies
function createCookie(name, value, minutes) {
if (days) {
var date = new Date();
date.setTime(date.getTime() + (minutes * 60 * 1000));
var expires = "; expires=" + date.toGMTString();
}
else var expires = "";
name = name;
document.cookie = name + "=" + value + expires + "; path=/";
}
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') c = c.substring(1, c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
}
return null;
}
Upvotes: 1
Reputation: 6359
setTimeout and jQyeryUI Modal Dialog will do the trick for you.
window.setTimeout(function () {
$("#myDialog").dialog("open");
}, numberOfMSToWaitBeforeOpening);
You'll need to to a little coding around management of the timeout when they close the dialog if you want a recurrence of the popup.
Upvotes: 0