HTML
HTML introduction
HTML basics
HTML colors
HTML backgrounds
HTML text
HTML font
HTML text formatting
HTML entities
Display tags
HTML links
Email links
Types of links
HTML images
HTML image maps
HTML tables
HTML frames
HTML forms
Fieldset/legend tags
HTML stylesheets
Div/span tags
HTML layout
HTML marquees
HTML multimedia
HTML meta tags
HTML document types
HTML base tag
HTML scripts
URL formatting
Encoding and decoding
HTML summary

Programming

Programming intro
Java

Markup

First webpage guide
XHTML

Style & Layout

CSS

Browser scripting

Javascript
VBScript
AJAX

Server scripting

PHP
ASP

Making money online

Make money online

HTML scripts

Scripts are not HTML but are comprised of various other languages such as Javascript and VBScript. However, HTML tags are used to place scripts on webpages.

This lesson focuses on:

The <script> tag

The <script> tag is used to place scripts on a webpage. When using the <script> tag, you have to use its type attribute to specify the language the script is written in.

Example:

<script type="text/javascript">
document.write("This is a script.");
</script>

This script specifies that the language it will be written in is Javascript.

The output of this script:

This is a script.

Handling browsers that cannot execute scripts

There are older browsers still in use that do not recognize the <script> tag and consequently will not be able to execute scripts. In such a case, the content inside the <script> tag will be displayed on the page as regular text. To prevent this from happening, the content of a script can be placed within comment tags. In such a case, older browsers that do not recognize the <script> tag will ignore the script and the content inside the <script> tag will not be displayed on the page. Browsers that can execute scripts will ignore the comments and execute the script anyway.

Example:

<script type="text/javascript">
<!--
document.write("Here is some text.");
-->
</script>

The output of this script:

Here is some text.

Another way to deal with browsers that do not support scripts is by using the <noscript> tag. This tag provides alternative text and/or contet to be displayed if a browser supports the <script> tag, but not the script inside it. If a browser does support the script inside a <script> tag then the text and/or content provided by the <noscript> tag will be ignored.

Example:

<script type="text/javascript">
<!--
document.write("This is a script.");
-->
</script>

<noscript>
You are using a browser that does not support Javascript!!
A great browser that does support Javascript is Mozilla 
Firefox. You can download it 
<a href="http://www.mozilla.org/firefox">here</a>
</noscript>

Examples

Placing a script on a webpage
This example demonstrates placing a script on a webpage.

Dealing with browsers that cannot execute scripts
This example demonstrates how to deal with browsers that cannot execute scripts.

See more script examples

Practice

Online code editor
Practical examples
Practical exercises
Step-by-step tutorials

Reference

Terms glossary
Reference material

Rate this site

Rate this site
Visitor comments