Launching fancybox on pageload only once (cookies)

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
Post Reply
porridj
Forum Members
Forum Members
Posts: 12
Joined: Wed Jan 07, 2009 3:04 pm

Launching fancybox on pageload only once (cookies)

Post by porridj »

Thanks to the help of Stikki we managed to make good use of the jQuery plugin fancy box. Loading once when the page has loaded, for an advert style popup that only comes up once every 7 days
You need:
jQuery
jQuery Fancybox plug in
jQuery cookies plug in

Code: Select all

<__script__ type="text/javascript">

function popup() {
         var COOKIE_NAME = 'supercookie';
        if($.cookie(COOKIE_NAME) != 'active') {
           $.cookie(COOKIE_NAME, 'active', { expires: 7 });
           $("a.fancybox").trigger("click");
      }
}

$(document).ready(function(){
 $("a.fancybox").fancybox({
    'overlayOpacity'  :  0.8,
	'autoScale' : false,
   	'overlayColor'    :  'black',
   	'overlayShow'    :  true
       });

 $('#s1').cycle('fade');
});
		
</__script>
So that bit goes in the ...sorting out the cookies and the fancy box, then it is just a case of following the instructions on how to install fancybox from their website.

Next you need to create a link within your page for the .trigger (click)
I couldnt get it to work without the link on the page but if you figure out a way round it let me know :)

and then finally

Code: Select all

</__body onload="popup()">
...and you are done!
Post Reply

Return to “Tips and Tricks”