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 9 of 9
  1. #1
    New to the CF scene
    Join Date
    Jul 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question external javascript

    I know this might be an odd question, but I haven't been able to find the answer anywhere.

    I have an enormous amount of javascript in my <head> section. I want to put them in an external file.

    I know I need to save them in Notepad as a text file. Here's what I don't know.

    Do I need to upload the file to the server first for it to work or should I be able to view it in the preview mode?

    I saved a file as mysite.js When I looked at the file in my documents in says it is JScript. Does that make any difference. And if it does, what should I do about it.

    I know not to use the <script></script> tags in the text file. One tutorial said to put comment tags <!-- at the start of the script and --> at the end. It was the only tutorial I found that mentioned that. Do I need to use the comment tags in the text file?

    Thanks,
    Shells

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,529
    Thanks
    3
    Thanked 511 Times in 498 Posts
    Its realy easy and vvery useful

    <!-- at the start of the script and --> are opional

    first try it locally on your pc with no file path in the same directory as the target HTML Page

    <script language="JavaScript" src="fred.js" type="text/javascript"></script>

    one you are happy it is sometimes good to put the External JavaScripts
    in a common directory for use by a number of documents. Then changes only need to be done once

    "Say

    <script language="JavaScript" src="MyJavaScripts/fred.js" type="text/javascript"></script>

    to be used by a number of documents

    as an aside
    if you are going to post a problem with a page javascript
    normally best to embed the script in the document, saves helpers hunting down the script.

  • #3
    New to the CF scene
    Join Date
    Jul 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks vw for the answer on the comment tags. That helped alot.

    Somethings take a little while to sink in...hehe

    Do I have to upload the file first for it to work or should it work locally?

    And

    When I save the file as a .js why does the folder icon say it's a JScript?

    This is what I'm using in the <head>

    <script language="JavaScript" src="MyDocument/filename.js">
    </script>

    One more thing... Why can't I justbuild it in my document root, like I do the css and php? I know...I know... I can use css and php, but can't figure out little ole javascript includes go figure

    shells
    Last edited by shells; 07-09-2005 at 09:30 AM.

  • #4
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,529
    Thanks
    3
    Thanked 511 Times in 498 Posts
    Do I have to upload the file first for it to work or should it work locally?
    first try it locally on your pc with no file path in the same directory as the target HTML Page
    When I save the file as a .js why does the folder icon say it's a JScript?
    PCs display the file type in all manner of ways


    Why can't I justbuild it in my document root, like I do the css and php?
    you can but

    to be used by a number of documents.
    Then changes only need to be done once

  • #5
    New to the CF scene
    Join Date
    Jul 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks again vw,

    It keeps saying it can't display page.

    The js file won't save under Text Document (*txt). It saves under "All Files"


    I know it should link just like an image tag, but for some reason it isn't.

    Thanks for your patience with me

    Shells

  • #6
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,529
    Thanks
    3
    Thanked 511 Times in 498 Posts
    Dont know what editor you are using

    For notepad save as a .txt then change extension to .js

  • #7
    Regular Coder
    Join Date
    Nov 2004
    Location
    The Netherlands
    Posts
    551
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Turn off "hide extensions for known files" in folder options.

    Also, remove the language="JavaScript". It's not needed. type="text/javascript" is enough.
    CATdude about IE6: "All your box-model are belong to us"

  • #8
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,529
    Thanks
    3
    Thanked 511 Times in 498 Posts
    ment to say

    if you are looking for a good text editor with syntax coloring

    try NotePad2 (free!)

    http://www.flos-freeware.ch/notepad2.html

  • #9
    New to the CF scene
    Join Date
    Jul 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm using Notepad.

    I saved it as .txt and then changed it to .js with the same outcome.

    I unchecked the "hide known extensions" in folder option and tried to save a different piece of script in Notepad. It's still saving in "All Files", says it is JSript script, and it says it is 204 bytes.

    It is a simple countdown script. Here is the script and how I have it entered in Notepad.

    <!--Hide from older browers
    //This function calculates the number of days until Christmas
    function XmasDays(Month, Day, Year) {
    var DayCount=(25-Day) + 31 + 30;
    return DayCount;
    }
    //Stop hiding-->

    PS vm, I checked out Notepad2 and I think I'm going to love it!

    Shells
    Last edited by shells; 07-11-2005 at 11:03 AM.


  •  

    Posting Permissions

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