1

How can I trigger a lightbox2 body on load. I need a popup when user enters a site.

Thanks in advance.

Subhojit Mukherjee
  • 701
  • 3
  • 10
  • 24

3 Answers3

1
    <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>
Ashfaq Shaikh
  • 1,648
  • 12
  • 20
0

I have a simple link, that includes "/lightbox2" at the end of url, and "rel" attribute.

<a id='popup' href="url/lightbox2" rel="lightframe">&nbsp;</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 :)

dark_kz
  • 33
  • 4
0

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/

Niels
  • 48,601
  • 4
  • 62
  • 81