Results 1 to 3 of 3

Thread: How To Create an External JS File?

  1. #1
    Join Date
    May 2005
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How To Create an External JS File?

    Hi,

    Can anyone give instructions, or know where I can find instructions, on creating an external java script file? Plain, precise, non-techy language would be best in my case, but any help at all will be appreciated.

    Thanks!

  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

    Do you mean write an external javascript from scratch or adapt an existing internal one to be used as an external one? From scratch is easy,

    Code:
    alert('Done!');
    Simply save the above code to a file and name it 'alertdone.js'
    Add this code to the head of your html page:

    Code:
    <script src="alertdone.js" type="text/javascript"></script>
    Adapting an internal script is similar but can get tricky depending upon the script. Many can be adapted simply by removing the '<script>' and '</script>' tags from the code, saving that code to a file and giving that file a name say, 'myscript.js', then putting this in the head or body (depending upon where the script was originally meant to go) of your page:
    Code:
    <script src="myscript.js" type="text/javascript"></script>
    Last edited by jscheuer1; 05-20-2005 at 09:00 PM.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by jscheuer1
    Many can be adapted simply by removing the '<script>' and '</script>' tags from the code [...]
    It should also be noted that SGML comments (<!-- ... -->), should be removed. So, given:

    Code:
    <script type="text/javascript">
      <!-- Hide from browsers
    
      /* Script content */
    
      // -->
    </script>
    only

    Code:
    /* Script content */
    should be saved. The SGML comments shouldn't be present anyway, but many old scripts haven't been updated to omit them.

    Mike

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
  •