...

View Full Version : Question about linking to a .js file.



cZone-Platinum
07-03-2003, 01:31 PM
==============================================

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! <(^_~)>

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

arnyinc
07-03-2003, 02:37 PM
I remember seeing a similar question recently and I think the type has to be equal to just "javascript" rather than "text/javascript".

ellisd5
07-03-2003, 02:38 PM
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

Roy Sinclair
07-03-2003, 03:54 PM
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.

cZone-Platinum
07-03-2003, 04:19 PM
Thanks! You people realy do help a lot!

sage45
07-03-2003, 04:23 PM
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-

sage45
07-03-2003, 04:28 PM
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-

arnyinc
07-03-2003, 04:36 PM
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* :o



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum