SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast kgish's Avatar
    Join Date
    Dec 2001
    Location
    Gouda, The Netherlands
    Posts
    64
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    CBE problems: inline vs. include

    Bored one morning, I decided to clean up some of my HTML code by taking the inline javascript code (including the CBE stuff), placing it in a separate "utils.js" file, and then using the script-tag to include it from the original spot.

    For some reason the CBE-specific code stops working when I do this.

    To give you a better idea what is happening, here is what the original code looks like before the cleanup action:

    Code:
    <body>
    <script type="text/javascript" src="cbe/cbe_core.js"></script>
    <script type="text/javascript" src="cbe/cbe_event.js"></script>
    <script type="text/javascript" src="cbe/cbe_slide.js"></script>
    <script type="text/javascript">
    <!--
    var e1;
    function windowOnload()
    {
    with (e1 = cbeGetElementById('E1').cbe)
    {
    	...
    }
     
    e1.sequence = new Array(
    "slideTo(...)",
    "slideBy(...)",
    ... 
    );
     
    ...
     
    e1.startSequence();
    ... 
    }
    //-->
    </script>
    In this situation, everything runs along just fine, e.g. upon loading the web page, the given sliding sequence above initiated by the call to "e1.startSequence()" is done as expected.

    Now I decide in my infinite wisdom to try the following:

    Code:
    <body>
    <script type="text/javascript" src="cbe/cbe_core.js"></script>
    <script type="text/javascript" src="cbe/cbe_event.js"></script>
    <script type="text/javascript" src="cbe/cbe_slide.js"></script>
    <script type="text/javascript" src="js/utils.js"></script>
    where the "utils.js" file contains the javascript code above, without the script-tag and comments stuff of course.

    However, even though I have not changed anything else, the sliding sequence no longer takes place. Weird.

    You might think that the "utils.js" file is not found, or that the relevant code is not called. But you are wrong, because when I stick a bunch of "alert()" function calls in the code, all of them get called.

    Seems that the "e1.sequence" array is not behaving properly anymore. Could it be that there is a subtle difference between inline javascript and included javascript? Perhaps the heavy use of eval might be getting in the way?

    I've heard of an IE timing bug where inline code is handled differently than included, but is this the same thing? How do I fix it then?

    Please help me (Mike Foster?).
    Kiffin
    Your average future-famous kind of guy...

  2. #2
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Kiffin,

    I don't see anything wrong with what you've posted. Is the page online?

  3. #3
    SitePoint Enthusiast kgish's Avatar
    Join Date
    Dec 2001
    Location
    Gouda, The Netherlands
    Posts
    64
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're absolutely right, Mike (as usual). I made a boo-boo, sorry about that.

    You see, while cutting and pasting the javascript code, I inadvertantly removed the document.write() stuff that generated the text inside of the id=E1 div-tag.

    That meant that while it was working just fine, I could not see it, because the contents of the sliding div tag was empty!

    Dumb, dumb.

    I guess that's what you deserve when going on and on into the wee hours of the morning just because you are an addicted javascript geek...

    Thanks anyway for your show of help.
    Kiffin
    Your average future-famous kind of guy...

  4. #4
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no problem Kiffin

    I guess that's what you deserve when going on and on into the wee hours of the morning just because you are an addicted javascript geek...
    That sounds like me!


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
  •