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

    Question Question about linking to a .js file.

    ==============================================

    Question:

    I have searched and cannot find a solution to my problem.
    Can any of you help me or give some helpful information?

    ==============================================

    Problem:

    I want to put all my JavaScripts in a .js file so that I can link
    to the file and not have to add every single JS to every page
    but when I do so the script(s) in the .js file do not take affect.
    The code below is what I used to link to the file:

    <SCRIPT type = "text/javascript" src="http://www.hostultra.com/~czoneplatinum/sitestuff/gate(body).js"></SCRIPT>

    Any replys would be very helpful.
    Thank You in advance! <(^_~)>

    ==============================================

  • #2
    Regular Coder
    Join Date
    Jan 2003
    Posts
    867
    Thanks
    4
    Thanked 8 Times in 8 Posts
    I remember seeing a similar question recently and I think the type has to be equal to just "javascript" rather than "text/javascript".

  • #3
    Regular Coder ellisd5's Avatar
    Join Date
    Jun 2002
    Location
    Uk
    Posts
    160
    Thanks
    5
    Thanked 0 Times in 0 Posts
    I would quess your paths wrong.

    Referencing a JS file is the same as referencing a image for example so it may not be nessercary to use the full path.

    Put a alert as the first thing in the js file. If it gets loaded then it should alert, just so you can test that its been found

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Don't forget, when calling Javascript from a separate file the file should contain only javascript. HTML code isn't allowed in the file. That means the <script> tags shouldn't be there and you definitely don't want the <!-- //--> html comment tags either.

    Type is text/javascript, that part is correct.
    Check out the Forum Search. It's the short path to getting great results from this forum.

  • #5
    New to the CF scene
    Join Date
    Jul 2003
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    ...

    Thanks! You people realy do help a lot!

  • #6
    Super Moderator sage45's Avatar
    Join Date
    May 2002
    Posts
    1,060
    Thanks
    0
    Thanked 13 Times in 13 Posts
    Something else that I spot is the "()"'s as part of the name of your file...

    Not always a problem but, as for naming files usually other than the use of the "_" and/or "&", spaces and other special charactors are usually avoided... Not only does it sometimes cause problems with FSO's but it also makes your code easier to proof read...

    Also, bear in mind that if you have any scripts that are object depended (the object must exist for it to modify before the script loads) that it might be best to leave them out of the external .js file, perhaps you can put them in their own external .js and reference them when you need them...

    HTH,

    -sage-
    HTML & CSS Forum Moderator

    "If you don't know what you think you know, then what do you know."
    R.I.P. Derrick Thomas #58
    1/1/1967 - 2/8/2000

  • #7
    Super Moderator sage45's Avatar
    Join Date
    May 2002
    Posts
    1,060
    Thanks
    0
    Thanked 13 Times in 13 Posts
    Originally posted by Roy Sinclair
    HTML code isn't allowed in the file. That means the <script> tags shouldn't be there and you definitely don't want the <!-- //--> html comment tags either.
    To clarify, what Roy means is that using tags as objects within the script is not allowed... However, using tags as part of an output string is perfectly legal...

    i.e. -

    document.write('<p>Paragraph one...<br //> We hold these truths to be... <br //>You get the idea...<//p>')

    -sage-
    HTML & CSS Forum Moderator

    "If you don't know what you think you know, then what do you know."
    R.I.P. Derrick Thomas #58
    1/1/1967 - 2/8/2000

  • #8
    Regular Coder
    Join Date
    Jan 2003
    Posts
    867
    Thanks
    4
    Thanked 8 Times in 8 Posts
    Originally posted by arnyinc
    I remember seeing a similar question recently and I think the type has to be equal to just "javascript" rather than "text/javascript".
    Sorry for misleading you. I'm sure seeing an answer under a question also tends to discourage some people from replying.

    My only defense is that I didn't proclaim my answer as gospel. I said "I think"!

    *smacky smacky*


  •  

    Posting Permissions

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