Results 1 to 3 of 3

Thread: One script causes another not to work

  1. #1
    Join Date
    Feb 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default One script causes another not to work

    1) Script Title:
    Facebox + external image gallery script

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

    3) Describe problem:

    My problem relates to scripts on this site as well as other scripts. I loaded both facebox script and a image gallery script from another site. It seems that having both externally linked scripts loaded at once will cause one or the other not to work. One script might not work if say another script is loaded, so it will have to be removed for the other script to work. Would anybody have any suggestions why this would happen? Perhaps duplicate function or prototype declarations...? Or maybe having more than one style sheet linked in could also be adding to the problem? I really enjoy a lot of these scripts especially modifying them to suite my needs, but this is a strange problem that i've never encountered before. Any help or suggestions would be greatly appreciated, thanks.

  2. #2
    Join Date
    Sep 2007
    Location
    The Netherlands
    Posts
    1,881
    Thanks
    49
    Thanked 266 Times in 258 Posts
    Blog Entries
    56

    Default

    Multiple onloads may cause problems. Here's a script that deals with it. Suppose you want to do the following onloads (which might conflict): onload1() and onload2(). Then you do:
    <script type="text/javascript">
    /*found at http://simonwillison.net/2004/May/26/addLoadEvent*/
    function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
    window.onload = func;
    } else {
    window.onload = function() {
    if (oldonload) {
    oldonload();
    }
    func();
    }
    }
    }
    addLoadEvent(function() {
    onload1();onload2()})
    </script>
    Last edited by molendijk; 02-09-2009 at 11:00 PM. Reason: Correction

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

    There is no onload conflict with Facebox, it uses the jQuery document.ready method, which in turn uses the addEvent/attachEvent methods, which don't conflict. Multiple stylesheets will only be a problem if the actual styles in them contradict each other. I'm guessing that you are using another library with the other script that conflicts with jQuery. jQuery can be run in no conflict mode though that doesn't always resolve all issues with other libraries. Often the best solution is to find a substitute for the other script, one that functions like it, but that uses the jQuery library.

    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

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
  •