Scripting languages are often included in the head section of a page. They are enclosed in the <script> ... </script> element. A typical example might look like this:

<script language="JavaScript" type="text/javascript">
<!--
function getsupport ( selectedtype )
{
  document.supportform.page.value = selectedtype ;
  document.supportform.submit() ;
}
-->
</script>

Because the script tag was introduced later in the deveopment of HTML the content of the tag is typically enclosed in a comment tag in order for it not to crash older browsers, though this protection is seldom needed today and may be overlooked by less sophistocated coders.

Scripting languages including AJAX, ECMAScript, Java, Javascript, XML, VBScript (by Microsoft and which only works in Internet Explorer), XSLT, and others can all be included in web pages. Cascading style sheets (CSS) is actually a form of interpreted scripting language but it is usually treated separately as we have seen elsewhere in this series of articles.

Most scripts that are positioned in the head section of the page may be moved off the page to external files and linked using the HTML <link /> tag. Here is an example of linking to a Javascript file:

<script type="text/javascript" src="/javascripts/getsupport.js"></script>

Such linking uses the <script> ... </script> element. The language attribute is not required though may be included. This method reduces the head section content by the number of lines that are included in the script plus the two used by the comment tag code. Linking to scripts may help SEO efforts considerably.


Discover more from Ultimate Virtual Solutions

Subscribe to get the latest posts sent to your email.