Forum Moderators: phranque

Message Too Old, No Replies

Javascripts question

external files...

         

robertito62

9:08 pm on Mar 29, 2003 (gmt 0)

10+ Year Member



I found some threads about it, but still can't make it work.

I have a long javascript file in the head of my HTML homepage I would like to link to externally, making SEs lives easier.

Not sure what I am doing wrong but it is not working.

Could someone help me get this right, starting with the proper link from homepage. where to put it, additional code in the body, etc?

The js file handles lots of rollovers and also it has been tweaked so that windows which open in a new browsers, remain open even after links on them have been selected (like an open menu).

The page also has applets with parameters which I would like to link to externally, making the file a lot smaller...

Thank you!

jimbeetle

9:17 pm on Mar 29, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Not sure about the applets and parameters so I can't help you there.

If the external js file is in the same directory you should not have a problem. However, if it's in a different directory than the page calling it you probably have to tweak some of the url references to reflect its new location as that's where the file is being run from. (Does that make sense?)

If that's still a problem try replacing any relative references with full urls and work backswards from there.

toadhall

1:27 am on Mar 30, 2003 (gmt 0)

10+ Year Member



> proper link, where to put it

In the head of the html file:


<script language="javascript" src="path_to/external_file.js"> </script>

...changing the file path to the path leading to your external file.

NB, the .js file does not need any <script> tags; just the code.

> additional code in the body

Only any that may be needed inline; events to call functions for instance.

More:
[webmasterworld.com...]
[webmasterworld.com...]

*Don't forget the Site Search facility at the top of every page at Webmasterworld!

T

robertito62

1:33 am on Mar 30, 2003 (gmt 0)

10+ Year Member



Thanks! I'll give it a try...

BlobFisk

12:56 pm on Mar 31, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just an addendum to toadhalls post. The language= attribute is deprecated and should be replaced with the type= attribute. So, for an external js file link:

<script type="text/javascript" src="source/to/file.js">