Things you want to know about websites

 

Scripts

Scripts are not Html but they are pieces of code written in scripting languages like php, perl, javascript etc. to perform a function.

There are basically two types of scripting,

  1. Server Side Scripting.
  2. Clinet Side scripting.

Server-side scripts are placed on web servers and they are executed by servers. While being executed they are not transferred to the visitor's computer but only their result is shown to the visitor.

Client-side scripts are not excuted by a web server, instead they are actually transferred to the visitor's computer where they are executed by the visitor's web browser.

In this guide we will see how to include client-side scripts to our html documents.

Client side Scripts

Client side scripting can produce dynamic pages or interactive pages i.e pages that can react to a user's action. You can make interactive buttons, interactive menus, small applications, validate form data and many things by using client-side scripts.

Javascript is the most popular client side scripting used, so we will see how to include javascript in our html document.

There are generally two types of scripts included in html documents.

  1. Internal scripts.
  2. External scripts.

Internal Scripts

Internal scripts are written inside an Html document. To include an internal script we use the <script> element.

Example

<script type="text/javascript">
document.write("I am a script")
</script>

Result

The above example uses the javascript to write some text on the screen.

External Scripts

External scripts are contained in a seperate file and they are called by the browser only when they are executed.

To include an external script, we use the script element with a src attribute.

Example

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

The above example uses an external script named script.js to do some function. The src attribute identifies the name and location of the file in the directory.

Preventing a script from executing automatically

A scripts is executed automatically when the browser reaches the line in the document where the scripts is placed, provided that the browser has the capabilities to execute the script.

This behaviour is not required always and we may want to run the script only on demand i.e when some event or action occurs.

We can do this by placing the script in the head section of the html document. In this way the scripts is not executed unless we call it through some event.

Information about using events is presented in the next section Html Events.

Noscript Element

You can create an alternate information for browsers that donot have javascript capability. In this case the information in the noscript element will be shown.

Example

<noscript>You browser cannot run scripts.</noscript>


Bookmark or Add to Favourites

Next :

Html-Events

Related :

Html-Meta

Link to this page :

Copy and paste the following code in an html document to link to this page,