|
|
||||||
|
||||||
| Index Link To US Private Messages Archive FAQ RSS | ||||||
| Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome. |
Share Thread: & Tags
|
||||
|
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
Hi everybody
Whenever you copy and paste a script, whether it be javascript or any other script, the instructions are always to include the <script> itself within the <head> tags. I sometimes find it easier to include the <script>***</script> somewhere in the middle of the page right above where you actually use the script. I have checked across various browsers and I cannot find any reason why it has to be within the <head> tags. It all seems to work regardless where you have the <script>. Does anybody know the reason? Does it really matter? Cheers |
|
||||
|
For the most part, its just good coding practice. As a coder I appreciate good coding practices. I have found that some scripts work better being embedded within the document. Some scripts won't work if they are not embedded in the <head>.
It depends on what you are doing.
__________________
Daniel M: South West Styles/STEELid daniel@steelid.com http://www.steelid.com http://www.thephototool.com |
|
||||
|
A Javascript will work anywhere in the <head> or <body> of a document. While it is preferential to put the JScript in the head of a document (and in a separate .JS where possible), sometimes it is necessary or easier to put the JScript into the body of the document (e.g. if you're dynamically generating an array of pics to be used in conjunction with a randomly rotated image section).
It may not provide output code that HTML coders would like, but for the actual programmers it may be easier to understand. As swstyles pointed out, some JScripts (such as a DHTML menu) will only work within the body of a document.
__________________
Toronto Web Design | Search Engine Friendly, Standards-Compliant Layouts | Walk on my Path (my blog) |
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
|
WebProWorld |
Advertise |
Contact Us |
About |
Forum Rules |
MVP's |
Archive |
Newsletter Archive |
Top |
WebProNews
WebProWorld is an iEntry, Inc. ® site - © 2009 All Rights Reserved Privacy Policy and Legal iEntry, Inc. 2549 Richmond Rd. Lexington KY, 40509 |