• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Scripts inside the head tag

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Are the scripts which are kept inside the <head> tag are automatically loaded ??

I am pasting my code of snippet here :

<head>
<script type="text/javascript">
function getXMLObject() //XML OBJECT
{
}
</script>
</head>
I know that if they are kept inside body , they need to be explicitly loaded using onload ? what about scripts inside the head tag ?
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Scripts inside the body do not have to be called with onload.

Eric
 
Steve James
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oh , i think my question is itself confusing . Let me make an another attempt "


Do the scripts mentioned inside the <head> tag automatically gets loaded ?
 
Ranch Hand
Posts: 607
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It does not make a difference to the script where they are kept - you can keep them in the head or body and it works the same way.

A script block consists of usually two components,
1 . Variable get loaded and function calls get executed without any additional call (like onload in the body).
2. Function definitions are not executed unless the function is called (you can call function from init() which itself is called onload of body!)

What you refer to when you mention that code in body is 'loaded ' using the onload method is a good practice that was followed (now the same is done using scriptless htlm - don't mix script and HTML) - it has nothing to do with where the script (body or head)is defined.
 
Have you no shame? Have you no decency? Have you no tiny ad?
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic