Results 1 to 5 of 5

Thread: Lightbox conflicting with another script?

  1. #1
    Join Date
    Jul 2005
    Location
    West Lothian, Scotland
    Posts
    37
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Lightbox conflicting with another script?

    1) Script Title: Lightbox image viewer

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamici...tbox/index.htm

    3) Describe problem:

    I am creating a photo album website and have been using the "Lightbox" image viewer script very successfully. I have come across one slight problem though - on the site's homepage only, I have also used a random image javascript to place one of a selection of pics at the top of the page when it loads or is refreshed. When I try to use Lightbox to display a pic on the homepage it will not work - the pic just opens up without the lightbox effect. It would appear that the random script and the Lightbox script are in conflict somehow as Lightbox works perfectly well on all the other pages.
    It is not a major headache for me if I cannot get Lightbox working on the homepage as it is not one of the main album pages but is there anything simple I can do to avoid this conflict of scripts and get it working?

    -- in Head section of homepage --

    <head>
    <link rel="stylesheet" href="lightbox.css" type="text/css" media="screen" />
    <script type="text/javascript" src="lightbox.js"></script>
    <SCRIPT LANGUAGE="JavaScript">
    <!-- Begin
    var randomTWD = 0;
    var DoIt = 0;
    images = new Array;
    images[1] = new Image();
    images[1].src = "pic1.jpg";
    images[2] = new Image();
    images[2].src = "pic2.jpg";
    images[3] = new Image();
    images[3].src = "pic3.jpg";
    images[4] = new Image();
    images[4].src = "pic4.jpg";
    images[5] = new Image();
    images[5].src = "pic5.jpg";
    images[6] = new Image();
    images[6].src = "pic6.jpg";
    images[7] = new Image();
    images[7].src = "pic7.jpg";
    images[8] = new Image();
    images[8].src = "pic8.jpg";
    images[9] = new Image();
    images[9].src = "pic9.jpg";
    images[10] = new Image();
    images[10].src = "pic10.jpg";
    images[11] = new Image();
    images[11].src = "pic11.jpg";
    images[12] = new Image();
    images[12].src = "pic12.jpg";
    images[13] = new Image();
    images[13].src = "pic13.jpg";
    images[14] = new Image();
    images[14].src = "pic14.jpg";
    images[15] = new Image();
    images[15].src = "pic16.jpg";
    images[15] = new Image();
    images[15].src = "pic16.jpg";
    function TWDpics() {
    var imgnum = images.length - 1;
    do {
    var randnum = Math.random();
    randomTWD = Math.round((imgnum - 1) * randnum) + 1;
    } while (randomTWD == DoIt);
    DoIt = randomTWD;
    document.ImageHolder.src = images[DoIt].src;
    }
    // End -->
    </script>


    -- In body section where random image displays --

    <img name="ImageHolder" src="clear.gif" width="600" height="200" border="0"></td>


    -- In body section where link to "Lightbox" photo is --

    <a href="photo.jpg" rel="lightbox">Click this photo</a>

  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

    Looks like you left something out. The random pics script will not do anything unless run. There is nothing in your code that shows it's being run. I'm guessing that you have something like so in your body tag:

    Code:
    onload="TWDpics();"
    If so, get rid of that. Put the lightbox script after the random pics script and add this to the end of the random pics script:

    Code:
    window.onload = TWDpics;
    Because lightbox will (at least in theory) add to an existing window.onload, making those changes and placing lightbox after it instead of before, should work out.

    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.
    - 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:

    Franco50 (10-28-2008)

  4. #3
    Join Date
    Feb 2008
    Posts
    137
    Thanks
    18
    Thanked 2 Times in 2 Posts

    Default

    Do you have a link or more code on what your random image thingy does?

    Hi jscheuer1, that was quick or I am slow.


    Cheers

  5. #4
    Join Date
    Jul 2005
    Location
    West Lothian, Scotland
    Posts
    37
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default

    John - thanks for the fast response! Yes, you're right I did forget to include this bit in my post .....

    <body onLoad="TWDpics();"

    I am at work just now but will try your recommendations when I get home and report back. I do not have the website 'live' as yet so cannot post a link as I am still working on the pages.

    Just one question, when you say Put the lightbox script after the random pics script and add this to the end of the random pics script: i take it you mean the parts between the [head] tags?

  6. #5
    Join Date
    Jul 2005
    Location
    West Lothian, Scotland
    Posts
    37
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default

    John - have just made your suggested changes and everything works perfectly. Thanks a lot!

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
  •