homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

Calling javascript from an external file into html body
How is it done?

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


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,



Bernard Marx

 12:05 am on Sep 21, 2004 (gmt 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 Sep 21, 2004 (gmt 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?


Bernard Marx

 1:28 am on Sep 21, 2004 (gmt 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 Sep 21, 2004 (gmt 0)

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

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved