A script is a program usually embedded in a webpage or accompany it. The script executes on the client’s browser when the document loads, or when a event takes place. HTML support different scripting language.
Scripts make a web page interactive and can execute when
- On a document load
- When a form is submitted to check input data
- Triggered by specific events like element focus, mouse movement etc.
There are two ways of using a script in an HTML document
External Script File – A separate file stores all the script functionality and is included in all the web pages on which the script functionality is to be used. It uses <script> tag in head section
Internal Script File – To apply script functionality to a single web page usually it is given in the header of the document using <script> tag for executing some functionality on web page loading or it can be placed anywhere in the web page as shown
It is an script or program which executes on specific event only usually on the UI event attributes like ‘onmouseover’, ‘onmousehover’ etc. as shown in example function ‘announce’ in header section is called when user hovers mouse over a heading
<title>Event Handler </title>
alert(“Hover on Heading….”);
Older browsers may not support scripts and the script code is shown to the user. HTML comments around the script are used so that older browsers avoid it as shown
It is used to give alternative text if browser do not support scripts or if scripts are disabled as shown