View Full Version : javascript in head?
espee2
July 9th, 2000, 03:04 AM
my code works, but it isn't in the <head> of my page, I read that javascript should go in the head of the page, but most pages I look at the source code and it is in the body of the page... where should I put my script?
------------------
espee2
Home: www.tunnel13.com (http://www.tunnel13.com)¤
layout: SP's Newberg Branch in N scale (http://tunnel13.com/newberg.html)
E-8
July 9th, 2000, 05:39 AM
Depends on what you want the script to do but normally in head.
------------------
Ship It On The FRISCO! (http://www.frisco.org)
Robin Matthysen
July 9th, 2000, 05:42 AM
Hi Espee2, I put my java script in the body of the page and I believe that is the only place you should put it that I know of anyway. I suppose it could be used elsewhere for special effects. On my home page, the script welcomes you by time of day.
http://www.trainboard.com/smile.gif
------------------
Robin
Maberly and Tayside (http://members.xoom.com/Matthyro/index.html)
espee2
July 9th, 2000, 05:59 AM
Thanks guys, here is some information I got from an alt.discuss.javascript group, and I think it is worth passing along:...
=========================================
...Put scripts any place you like, head or body.
The only reasons most people put scripts in the head is because browsers read like we do, from left to right and from top to bottom. If a script is in the head, it's fully loaded 1st before a visitor has a chance to press a button or link located in the body, and fire up a script function before it has been fully loaded.
Then the script might not work. So always load your scripts before the user can fire them up.
Plus by putting scripts in the head where little other stuff is, it frees up the body area for the html stuff. In short, it's much neater too.
Personally I prefer to build functions in the head, and define variables there too. But sometimes you have to write scripts in the body. Either way will work and is considered OK. Just make sure scripts load before users can stoke them. It's even proper to use both ways on one page. It just depends on what your script does..."
=========================================
sounds good to me!
------------------
espee2
Home: www.tunnel13.com (http://www.tunnel13.com)¤
layout: SP's Newberg Branch in N scale (http://tunnel13.com/newberg.html)
vBulletin® v3.8.0 Beta 2, Copyright ©2000-2008, Jelsoft Enterprises Ltd.