You don't specify whether you want to run the blockUI:
- Only once the first time a user visits the site. If so, check if a cookie is set before running the blockUI code, and then set it after running the code. See Create a cookie if (and only if) it doesn't already exist.
- Only once every time the user visits a specific page on the site. If so, just set and check a cookie on that page. Otherwise, use a div (e.g.
homediv
) specific to that page and put the code in a load function for that: $('#homediv').load(function () { //put the logic above here });
Edit
If it is the first one, and you only want to show the message once a week to visitors to the site, then try the following:
jQuery(document).ready(function() {
if($.cookie('firstvisit') == null) {
jQuery.blockUI({
message: 'Blah blahblah',
timeout: 15000
});
$.cookie('firstvisit', '0', {expires:7, path:'/'});
}
});
Change the 7
to the number of days to pass before you want to show the message again.