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
- Handling browsers that cannot execute scripts
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:
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:
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.




