Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Two JS codes in one page, only bottom working

    I am trying to use these two js codes in one page:


    http://acrisdesign.com/2010/03/jquer...on-hoverclick/

    http://www.huddletogether.com/projects/lightbox2/

    They both work perfectly fine except when both linked up at the same time. Only the last one will work. I've tried to find how the codes are working when the page loads in order to fix that problem but I cant figure it out for these two specific codes.

    Thanks.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    This has been covered very many times in this forum.

    There are three reasons which two scripts on the same page may conflict:-

    a) Multiple onload statements. See:-
    http://www.javascriptkit.com/javatut...iplejava.shtml
    http://www.dyn-web.com/tutorials/combine.php
    Or to resolve you can simply fire a set of functions when the page loads.
    Code:
    <script type="text/javascript">
    window.onload = function() {
    functionOne();
    functionTwo();
    }
    </script>
    b) Duplicate function and/or variable names in the scripts - the second instance will overwrite the first.
    c) Using two or more different Javascript frameworks.

    "If you think education is expensive, try ignorance." - Derek Bok (1930-), Harvard University President

  • #3
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for responding.

    I have tried entering that code already to see if that would work and it didn't help. I also tried to figure out those last two scenarios but I haven't been able to.

    If anyone could point me in the right direction as far as the two specific sources I posted, that would be amazing.

    Thanks again

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    If you use the search feature of this forum for "lightbox" you will find that the same problem has arisen several times before - and a satisfactory solution has not been found.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •