Web Analytics Made Easy -
StatCounter external .js files - CodingForum

Announcement

Collapse
No announcement yet.

external .js files

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • external .js files

    Hi all,

    OK, I have a number of roll-overs coded into my site pages. I have been able to ship out the functions into a single external .js file without a problem.

    However, when I try and remove the image definitions and .src references for the rollover images, it doesn't work. Does anybody know if I can ship out something like:

    if (document.images)
    { image1 = new Image; image2 = new image;
    image1.src = "../images/image1.gif"; image2.src = "../images/image2.gif" }

    into an external .js file? It doesn't seem to be working for me and I was wondering if there was a workaround or if I can't do it at all.

    Thanks,

    Azz
    code, debug, dubug, debug, *SIGH* debug, debug ...

  • #2
    Remeber the new Image is a constructor, it should be new Image();

    Add the parens, and remember the "I" needs to be caps.

    That should do it for you.

    You also might try changing the if to:

    if(document.images.length>0)
    Last edited by bcarl314; Jun 28, 2002, 10:07 AM.
    Create accessible online surveys -::- Koobten.com - compare netbook prices and reviews -::- Affordable, reliable hosting for less than $20 per year
    Zend Certified Engineer

    Comment


    • #3
      Hi there,

      Thanks for that - sorry I typed it in wrong.

      I seemed to have solved my problem, though - there were a few comments in the code being copied across - I removed these and it worked beautifully!

      Can you not comment external .js files then?

      Thanks for the input

      Azz
      code, debug, dubug, debug, *SIGH* debug, debug ...

      Comment


      • #4
        Originally posted by Azzkika
        .....Can you not comment external .js files then?

        Thanks for the input

        Azz
        You can comment in external .js files, as long as you don't comment out the wrong thing .

        For example, in your .js file you could comment like this and you'll still get the alert:

        alert('Hello World!'); // This is an alert

        But this would comment out the alert:
        // alert('Hello World!');

        For multiple lines:

        /*The following is
        a simple alert
        of Hello World*/

        alert('Hello World!');

        What did the comments in your.js file look like ?
        boxer_1
        CodingForum Moderator
        "How did a fool and his money get together in the first place?"

        Comment


        • #5
          Hmmm...

          That's interesting.



          The comments were like so:

          if (document.images)
          {
          // comment here
          PjMOff = new Image;
          PjMOn = new Image;

          BAOff = new Image;
          BAOn = new Image;

          PgMOff = new Image;
          PgMOn = new Image;
          // comment here
          PjMOff.src = "../images/PjMIconOff.gif"
          PjMOn.src = "../images/PjMIconOn.gif"

          BAOff.src = "../images/BAIconOff.gif"
          BAOn.src = "../images/BAIconOn.gif"

          PgMOff.src = "../images/PgMIconOff.gif"
          PgMOn.src = "../images/PgMIconOn.gif" }

          It should have been OK, yeah?

          Azz
          code, debug, dubug, debug, *SIGH* debug, debug ...

          Comment


          • #6
            Should have been, but as bcarl314 mentioned 'new Image' should be 'new Image()'. You say after you removed the comments it worked fine. Are you sure it's not just because the images are cached, making the rollovers appear as though they were instant because it was drawing the image from the cache?

            If you haven't already, try clearing your cache/tmp internet files and see if the rollovers are still instantaneous .
            boxer_1
            CodingForum Moderator
            "How did a fool and his money get together in the first place?"

            Comment


            • #7
              Strange...

              did the full cache clear out thing and it didnt seem to make any difference to the rollover time - no delays at all. Oh well ... I'll try adding those paretheses and see what happens ...


              Thanks for the help once again

              Azz
              code, debug, dubug, debug, *SIGH* debug, debug ...

              Comment


              • #8
                2 other quick things

                1) About the comments, make sure that if your using a text-editor and you have word wrap on that the comments are on new lines. (Just put a return in if you need to)

                2) If you are testing this on our own box, your computer is fast enough talking to itself that it may appear the roll-overs are instant, but when you upload over a server and need to connect at a slower speed, you'll see the change.
                Create accessible online surveys -::- Koobten.com - compare netbook prices and reviews -::- Affordable, reliable hosting for less than $20 per year
                Zend Certified Engineer

                Comment


                • #9
                  interesting...

                  I'll test it on my 56K line on my PII 200 at home later - that should show up any slowness.

                  Have a look at the site and see if you guys can detect anything (just don't use NS whatever you do - haven't optimised for that yet!) - the main index page is the one with the external .js!

                  www.nemeaconsulting.co.uk

                  Cheers, guys - thanks for that!

                  Azz
                  code, debug, dubug, debug, *SIGH* debug, debug ...

                  Comment

                  Working...
                  X