Welcome to WebmasterWorld Guest from 54.146.180.94

Forum Moderators: open

Calling javascript from an external file into html body

How is it done?

   
10:51 pm on Sep 20, 2004 (gmt 0)

10+ Year Member



Hi,

For anyone who has a largish javascript written into their HEADER, it's best to place it in an external file and call it into the header using <script type="text/javascript" src="whatever.js"></script>.

I know that javascript can also be placed in an external file to call into the BODY of a page because google ads do it.

I'm currently trying to take a javascript out of the body of an html page and call it from an external .js file. I keep getting scripting errors though.

Does anyone know how to do this?

Thank you,

Doug

12:05 am on Sep 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just stick it in the body.

If you're getting errors, it's because of the specific content of the script.
Quoting the actual errors might be a start.

12:26 am on Sep 21, 2004 (gmt 0)

10+ Year Member



Thanks for your reply Bernard,

The error I get from my HTML editor (HTML-Kit) just says "syntax error".

When you say just stick in in the body, I guess you're meaning to put <script type="text/javascript" src="george.js"></script> into the body and that this should work?

Doug

1:28 am on Sep 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, that's it.

For a better error message, try running it in a (real) browser.
A Mozilla browser may give you a better message from the Javascript console.

Comment out the whole script with a multi-line comment (/* */). Then shift the /* a few lines at a time until the error appears. This way, you'll narrow it down.

3:40 am on Sep 21, 2004 (gmt 0)

10+ Year Member



Hi again and thanks for your help - it works exactly as you said it would.
 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month