Welcome to WebmasterWorld Guest from 54.144.112.127

Forum Moderators: open

Message Too Old, No Replies

Calling javascript from an external file into html body

How is it done?

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

New User

10+ Year Member

joined:Aug 17, 2004
posts:35
votes: 0


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 Sept 21, 2004 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 15, 2004
posts:2047
votes: 0


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 Sept 21, 2004 (gmt 0)

New User

10+ Year Member

joined:Aug 17, 2004
posts:35
votes: 0


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 Sept 21, 2004 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 15, 2004
posts:2047
votes: 0


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 Sept 21, 2004 (gmt 0)

New User

10+ Year Member

joined:Aug 17, 2004
posts:35
votes: 0


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

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members