Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q421 What is the difference between writing a JavaScript into <HEAD> </HEAD> and <BODY> </BODY> tags?

You are here: irt.org | FAQ | JavaScript | General | Q421 [ previous next ]

Its a good idea to place all your JavaScript function definitions within the HEAD elements, that way you are 100% certain that they are defined before they are used - especially important if they are invoked via an event handler.

When using JavaScript in a frameset you must place all the JavaScript with the HEAD elements otherwise you cannot guarantee that the frames will be displayed correctly - this is especially true for Microsoft Internet Explorer.

Placing JavaScript code in tables can cause problems on some browsers. The trick here is to make sure the whole of a table row is output from JavaScript rather than just the contents of the table row.

If you output to the document from JavaScript before the BODY tag, then in effect your starting the body of the page earlier in your document than any actual BODY tag in the code. This may cause other elements that should be positioned prior to the BODY tag, e.g. TITLE, META etc, to not be processed correctly.

Apart from that you can place JavaScript almost anywhere in a document.

©2018 Martin Webb