script
Definition and Usage
The HTML <script> tag is used for declaring a script (such as JavaScript) within your HTML document. The <script> tag is used to define a client-side script, such as a JavaScript. A client-side script is a program that may accompany an HTML document or be embedded directly in it. The program executes on the client's machine when the document loads, or at some other time such as when a link is activated. HTML's support for scripts is independent of the scripting language. The <script> element either contains scripting statements, or it points to an external script file through the src attribute. Common uses for JavaScript are image manipulation, form validation, and dynamic changes of content. A script is a small piece of program that can add interactivity to your website. For example, a script could generate a pop-up alert box message, or provide a dropdown menu. This script could be Javascript or VBScript. You can write your Event Handlers using any of the scripting language and then you can trigger those functions using HTML attributes. There are two ways of using a style sheet in an HTML document:External Script:
If you have to use a single script functionality among many HTML pages then it is a good idea to keep that function in a single script file and then include this file in all the HTML pages. You can incluse a style sheet file into HTML document using <script> element. Below is an example:
<head> <script src="yourfile.js" type="text/javascript" /> </head> |
Internal Script:
You can write your script code directly into your HTML document. Usually we keep script code in header of the document using <script> tag, otherwise there is no restriction and you can put your source code anywhere in the document. You can specify whether to make a script run automatically (as soon as the page loads), or after the user has done something (like click on a link). Below is an example this would write a Hello Javascript! message as soon as the page loads.:
<head> <title>Internal Script</title> </head> <body> <script type="text/javascript"> document.write("Hello Javascript!") </script> </body> |