Question

I'm using this snippet for blockUI (jQuery plugin) to display a 'blahblah' text for 15 seconds, then it automatically disappears and unlocks the page.

 <script>
 jQuery(document).ready(function() { 

         jQuery.blockUI({ 
             message: 'Blah blahblah', 
             timeout: 15000 
         }); 
 }); 
 </script>

Is there a way to display this just on first page load and not on every page of the site..?

Thanks in advance! :)

Was it helpful?

Solution

You don't specify whether you want to run the blockUI:

  1. 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.
  2. 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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top