How can I trigger a lightbox2 body on load. I need a popup when user enters a site.
Thanks in advance.
How can I trigger a lightbox2 body on load. I need a popup when user enters a site.
Thanks in advance.
<script type="text/javascript">
// Automagically load Lightbox on Page Load - by Bramus! (http://www.bram.us/)
// Code modded from http://www.huddletogether.com/forum/comments.php?DiscussionID=1269&page=1#Item_0
function autoFireLightbox() {
//Check if location.hash matches a lightbox-anchor. If so, trigger popup of image.
setTimeout(function() {
if(document.location.hash && $(document.location.hash.substr(1)).rel.indexOf('lightbox')!=-1) {
myLightbox.start($(document.location.hash.substr(1)));
}},
250
);
}
Event.observe(window, 'load', autoFireLightbox, false);
</script>
I have a simple link, that includes "/lightbox2" at the end of url, and "rel" attribute.
<a id='popup' href="url/lightbox2" rel="lightframe"> </a>
And js something like this:
<script type='text/javascript'>
$(function() {
$('#popup').trigger('click');
});
</script>
To show it once, or for a while I use jQuery.cookie :)
Or something like this:
$(function(){
// Link to open
$("#link").click();
});
You do need to initialize the fancybox first before you can open the fancybox.
Live demo: http://jsfiddle.net/Y554b/1/