gridsystems
10-26-2009, 01:24 PM
HI,
I am quite new to javascript but with the help of jscheuer1's comment in this thread (http://www.dynamicdrive.com/forums/showpost.php?p=163248&postcount=15) I managed to get a Lightbox 2.04 working to display a single image when a page loads.
Basically I put this
<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:
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!
I am quite new to javascript but with the help of jscheuer1's comment in this thread (http://www.dynamicdrive.com/forums/showpost.php?p=163248&postcount=15) I managed to get a Lightbox 2.04 working to display a single image when a page loads.
Basically I put this
<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:
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!