HTML Scripts, HTML Tutorial, Global Guideline

Bookmark Bookmark: HTML Scripts, HTML Tutorial
Forum | Blog


      Home                    

Basic HTML Guide.      
 HTML Introduction.      
 HTML Entities.             
 HTML Tags Guide.      
 HTML Head.                
 HTML Meta.                
 HTML Styles.               
 HTML Formatting.       
 HTML Backgrounds.     
 HTML Attributes.         
 HTML Links.                
 HTML Tables.             
 HTML Images.            
 HTML Colors.              
 HTML Fonts.               
 HTML Marquee.         
 HTML Forms.             
 HTML Frames.           
 HTML Lists.                
 HTML Scripts.  
 HTML Summary.        

HTML Tutorial >> HTML Scripts.


     Back             Next     



Purpose of HTML Script

This HTML Tutorial section will explain the HTML with JavaScript tag, HTML Script Tag has two purposes:
  1. It identifies a block of script in the page.
  2. It loads an external JavaScript file.

Which it does depends on the presence of the src attribute. A </script> close tag is required in either case.

A script tag can contain below attributes:

src="url"

The src attribute is optional. If it is present, then its value is a url which identifies a .js (JavaScript) file. The loading and processing of the web page pauses while the browser fetches, compiles, and executes the file. The content between the <script src="url"> and the </script> should be blank.

If the src attribute is not present, then the content text between the html <script> and the </script> is compiled and executed. The script should not contain the sequence

</

because it could be confused with the </script>. Inserting a backslash between < and / in strings avoids the problem.

<\/

The backslash will be ignored by the JavaScript compiler.

Do not use the <!-- //--> hack with scripts. It was intended to prevent scripts from showing up as text on the first generation browsers Netscape 1 and Mosaic. It has not been necessary for many years. <!-- //--> is supposed to signal an HTML comment. HTML Comments should be ignored in JavaScript, not compiled and executed. Also, HTML comments are not to include --, so a script that decrements has an HTML error.

language="JavaScript"

This attribute has been deprecated. It was used to select other programming languages and specific versions of JavaScript. You don't need it. Don't use it.

type="text/JavaScript"

HTML Script attribute type is optional. Since Netscape 2, the default programming language in all browsers has been JavaScript. In XHTML, this attribute is required and unnecessary. In HTML, it is better to leave it out. The browser knows what to do.

defer

HTML Script attribute defer was intended to alter the timing of component loading in pages. It is not well supported and should not be used.

for="name" event="name"

HTML Script attributes for and event are Microsoft feature for declaring event handlers using HTML Scripts. It is not standard. Don't use it now. 

Placement of HTML Scripts

A <script src="url"></script> will block the downloading of other page components until the script has been fetched, compiled, and executed. It is better to call for the JavaScript as late as possible, so that the loading of images and other components will not be delayed. This can improve the perceived and actual page loading time. So it is usually best to make all <script src="url"></script> the last features before the </body>. An in-page HTML <script> does not have a significant impact on loading time.

If a html script is defining functions or data that are used by other functions, then the defining must be done before use. So the defining scripts must come before the using scripts.

document.write("HTML Tutorial section of HTML Script at Global Guide Line");

The document.write method provides a way of incorporating strings into the HTML content of the page. There are better ways to do that, such as .innerHTML and .createElement or HTML cloning patterns. Use of document.write should be avoided.

HTML Script of document.write is recklessly dependent on timing. If document.write is called before the onload event, it appends or inserts text into the page. If it is called after onload, it completely replaces the page, destroying what came before.

HTML Tutorial explains here that document.write encourages bad structure, in which html script and markup are intermingled. A cleaner structure has minimal interaction between markup and script.


Required Attributes for HTML Scripts

  • type is used to specify what type of scripting language is used. This takes the form of a MIME type such as text/javascript.
 

Optional Attributes for HTML Scripts

  • src can be used to specify an external source of a script file.
  • charset can be used to specify the character set of the element.
  • defer can be used to specify that the script does not generate any document content so that the browser doesn't have to worry about it while the page loads. It must be used in the format defer="defer".
 

HTML Scripts Example

<script type="text/javascript" src="somescriptfile.js"></script>
<script type="text/javascript">
   function showMessage() {
      alert(' Well Come at Global Guide Line HTML Tutorial section of HTML Scripts');
   }
</script>
 

For more details of HTML Scripts you need to visit our JavaScript section, where you will find how to use Script in a web page and how to utilize the functionality of HTML Scripts in your web site to enhance the performance of your site.


     Back             Next     
 

[ About ] [ Contact ] [ Home ]
[ Links ] [ Site Map ] [ Services ] [ Privacy ]

Copyright 2005 -  2018 www.globalguideline.com All rights reserved. (Best viewed in IE 6.0+ or Firefox 2.0+ at 1024 * 768 or higher) 184 visitors are online now