Please visit our sponsors !
HTML Scripts
Add scripts to HTML pages to make them more dynamic and
interactive.
Examples
Insert a script
This example demonstrates how to insert a script into your HTML document.
Work with browsers that do not support scripts
This example demonstrates how to handle browsers that do not support scripting.
Insert a Script into HTML Page
A script in HTML is defined with the <script> tag. Note that you will
have to use the type attribute to specify the scripting language.
<html>
<head>
</head>
<body>
<script type="text/javascript">
document.write("Hello World!")
</script>
</body>
</html>
|
The script above will produce this output:
Hello World!
Note: To learn more about scripting in HTML, visit our JavaScript
School.
How to Handle Older Browsers
A browser that does not recognize the <script> tag at all, will display
the <script> tag's content as text on the page. To prevent the browser from
doing this, you should hide the script in comment tags. An old browser (that does not
recognize the <script> tag) will ignore the comment and it will not write
the tag's content on the page, while a new browser will understand that the
script should be executed, even if it is surrounded by comment tags.
Example
JavaScript:
<script type="text/javascript">
<!--
document.write("Hello World!")
//-->
</script>
VBScript:
<script type="text/vbscript">
<!--
document.write("Hello World!")
'-->
</script>
|
The <noscript> Tag
In addition to hiding the script inside a comment, you can also add a <noscript>
tag.
The <noscript> tag is used to define an alternate text if a
script is NOT executed. This tag is used for browsers that recognize the
<script> tag, but does not support the script inside, so this browser will
display the text inside the <noscript> tag instead. However, if a browser supports
the script inside the <script> tag it will ignore the <noscript>
tag.
Example
JavaScript:
<script type="text/javascript">
<!--
document.write("Hello World!")
//-->
</script>
<noscript>Your browser does not support
JavaScript!</noscript>
VBScript:
<script type="text/vbscript">
<!--
document.write("Hello World!")
'-->
</script>
<noscript>Your browser does not support VBScript!</noscript>
|
Script Tags:
NN: Netscape, IE: Internet Explorer, W3C: Web Standard
Start Tag |
NN |
IE |
W3C |
Purpose |
<script> |
3.0 |
3.0 |
3.2 |
Defines a script |
<noscript> |
3.0 |
3.0 |
4.0 |
Defines an alternate text if the script is not executed |
<object> |
|
3.0 |
4.0 |
Defines an embedded object |
<param> |
3.0 |
3.0 |
3.2 |
Defines run-time settings (parameters) for an object |
<applet> |
|
|
|
Deprecated. Use <object> instead |
Jump to: Top of Page
or HOME or
Printer friendly page
Search W3Schools:
What Others Say About Us
Does the world know about us? Check out these places:
Dogpile
Alta Vista
MSN
Google
Excite
Lycos
Yahoo
Ask Jeeves
We Help You For Free. You Can Help Us!
W3Schools is for training only. We do not warrant its correctness or its fitness for use.
The risk of using it remains entirely with the user. While using this site, you agree to have read and accepted our
terms of use and
privacy policy.
Copyright 1999-2002 by Refsnes Data. All Rights Reserved
|