Results 1 to 4 of 4

Thread: how write cookie (to manage a lightbox)

  1. #1
    Join Date
    Oct 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default how write cookie (to manage a lightbox)

    HI,

    I am quite new to javascript but with the help of jscheuer1's comment in this thread I managed to get a Lightbox 2.04 working to display a single image when a page loads.

    Basically I put this
    HTML Code:
    <div><a id="lightboxPopImage" href="images/welcome_first_timer.jpg" rel="lightbox"></a> </div>
    at the end of the xhtml-code on my landing page, and then added two lines of code to the lightbox.js, so that it looks like this:
    Code:
    var th = this;
            (function(){
                var ids = 
                    'overlay lightbox outerImageContainer imageContainer lightboxImage hoverNav prevLink nextLink loading loadingLink ' + 
                    'imageDataContainer imageData imageDetails caption numberDisplay bottomNav bottomNavClose';   
                $w(ids).each(function(id){ th[id] = $(id); });
                if (document.getElementById('lightboxPopImage')) {
                    th.start(document.getElementById('lightboxPopImage'));
                }
            }).defer();
    
        },
    This way I get a lightboxpopup every time the page loads.

    But of course I would like to take it one step further, and use a cookie to control that this lightbox effect is only performed once per day. I have been battling with trying to implement a cookie solution all weekend but just have not got it to work (even started to look at PHP cookies in my desperation).

    I think I just need a very simple routine inside the lightbox.js that checks for the existence of a cookie, and if it finds a cookie it skips the parts in the script where it shows the image, and just aborts the script altogether.

    And then at the end of lightbox.js I guess I need to create the cookie in question (with a longevity of 1 day). At the end since I want to give the lightbox the chance to execute for a first time visitor before the cookie is created.

    Is this difficult? Is it much to ask for help on this matter?

    I would be very happy to get some pointers.
    I enclose the full sized lightbox.js

    Thanks a lot from Sweden!

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

  3. #3
    Join Date
    Oct 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    John,

    What an utterly slick adaptation! Really nice. The only downside to it is that I did not get the chance of learning more javascript by solving the problem with the help of someone, but heck I can't complain at all. Now I have more time to read those two books I bought from scratch...

    Thanks again for your reply and your smooth extension of the lightbox.

    /Peter

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    If you want more on just cookies see:

    http://www.dynamicdrive.com/forums/blog.php?b=32

    And for a bit more of an explanation of how they work (but less efficient code):

    http://www.quirksmode.org/js/cookies.html
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •