JavaScript Tutorials - Herong's Tutorial Examples - 2.33, by Herong Yang
Using HTML Entities to Protect HTML Tags
This section provides a tutorial example on how to use HTML entities < and > to protect HTML tags
To completely resolve the problem we saw in the previous section, we need to use HTML entities to replace '<' and '>', if you want some HTML tags to be displayed as page content.
Here is the revised HTML document using < and > entities:
<html> <!-- Escape_Script_Tag_HTML_Entity.html Copyright (c) 2002 HerongYang.com. All Rights Reserved. --> <head><title>Escaping Script Tags</title></head> <body><pre> <script type="text/javascript"> document.writeln("Q: How to use the <script> tag?"); document.writeln("A: <script>...Code...<\/script>"); document.writeln("Rate this answer: 1 | 2 | 3 | 4 | 5"); </script> </pre></body> </html>
If you run this example script in a browser, you will get:
Q: How to use the <script> tag? A: <script>...Code...</script> Rate this answer: 1 | 2 | 3 | 4 | 5
Finally, we get what we want!
Table of Contents
ECMAScript Language Specification and JavaScript Dialects
Data Types, Variables and Expressions
Creating, Accessing, and Manipulating Arrays
Defining and Calling Functions
►Web Browser Supporting JavaScript
JavaScript Support in Web Browsers
Including JavaScript Codes with HTML "script" Tags
type="text/javascript" or language="JavaScript"
JavaScript Version Supported by Browsers
Including 'script' Tags in String Literals
Escaping 'script' Tags in String Literals
►Using HTML Entities to Protect HTML Tags
Including JavaScript Codes as External Files
DOM API - The "document" Object
DOM API - The "window.open" Method
'javascript:' Pseudo-URL Addresses
JavaScript Console in Google Chrome
JavaScript Console in Mozilla Firefox
JavaScript Console in Apple Safari
JavaScript Console in IE (Internet Explorer)
Server-Side and Client-Side Web Scripting
Defining Your Own Object Types
Inheritance of Properties and Methods through the Prototype Object Chain
'jrunscript' - JavaScript Shell Command from JDK
Using Functions as "Function" Objects
Introduction to Built-in Object Types
W3C's Document Object Model (DOM) Specifications