Results 1 to 5 of 5

Thread: Lightbox on images loaded using Ajax?

  1. #1
    Join Date
    May 2008
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Lightbox on images loaded using Ajax?

    Hi,

    I'm currently using Litebox on a few pages of my site, called in via a Javascript if statement, checking if the item 'profilepic' is on the page:

    Code:
    function checklightbox() {
    	if(document.getElementById('profilepic')) { initLightbox(); }
    }
    This is fine, except on one of the pages there's a list of links that'll change the picture that's displayed, so as soon as you click the link, and the ajax calls in the new picture, the Litebox script doesn't work at all, as if it isn't initialised on that page, and Firebug says:

    myLightbox is not defined
    [Break on this error] anchor.onclick = function () {myLightbox.start(this); return false;}
    Any help or advice on how to get this working would be fantastic.

    Cheers

  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

    Default

    First off, the litebox script and its resources files should be on the top page. And you should initialize lightbox onload once, just as you would with a normal non-AJAX page. Now on your page that is imported via AJAX, with the new lightbox links on it, make them all look like so:

    HTML Code:
    <a href="some.jpg" rel="lightbox" onclick="myLightbox.start(this);return false;">
    This works well with the original lightbox, and from looking at the script for litebox, should work fine for it too. You don't want repeated initializations of lightbox anyway. In some browsers this will mess up the lightbox display or cause other problems.
    - John
    ________________________

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

  3. The Following User Says Thank You to jscheuer1 For This Useful Post:

    blizeH (05-13-2008)

  4. #3
    Join Date
    May 2008
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Many thanks for the reply, I've currently got the Litebox files included at the top of the page, and then this further down:

    Code:
    <a onclick="myLightbox.start(this);return false;" rel="lightbox[emp]" href="../users/010000P.JPG"><img id="profilepic" src="../users/010000P.JPG"/></a>
    
    <script type="text/javascript">initLightbox();</script>
    For some reason it still isn't working, and it's bringing up the exact same error as earlier
    Last edited by blizeH; 05-13-2008 at 12:42 PM.

  5. #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

    According to the litebox instructions, you should only initLightbox(); once, in the body tag's onload event. If you want more help:

    Please post a link to the page on your site that contains the problematic code so we can check it out.


    Explain all of what I must do, and in what browser, to duplicate the problem.
    - John
    ________________________

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

  6. #5
    Join Date
    May 2008
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Many thanks for the reply, unfortunately it just doesn't seem to initialise properly. I tried slimbox, and that didn't work either, but the code to do it manually worked a treat when I used onclick with the image. Only drawback is that it doesn't work without Javascript, but in all honesty, the entire page is shoddily built and won't work without Javascript anyway, so it shouldn't matter too much

    Thanks again for your help John, really appreciate it.

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
  •