Click Here!
home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

HTML 4.0 Sourcebook
(Publisher: John Wiley & Sons, Inc.)
Author(s): Ian S. Graham
ISBN: 0471257249
Publication Date: 04/01/98

Bookmark It

Search this book:
 
Previous Table of Contents Next


HTTP-EQUIV Attribute Usage

HTTP-EQUIV lets the document contain HTTP-header information, which can be accessed (and used to generate the HTTP response) either by the server delivering the document, or by the browser receiving the document. An example is:

<META HTTP-EQUIV=“Creation-Date” CONTENT=“23-Sep-94 18:28:33 GMT”>

which indicates the creation date of the document, in the context of the appropriate HTTP header field Creation-Date . If the server actually parses the document head, then it will create an HTTP header field

Creation-Date: 23-Sep-94 18:28:33 GMT

and include this with the HTTP response header that precedes the document during an HTTP transaction (see Chapter 9). Even if the server does not create such a header, a browser or other program can still obtain this information directly from the META element.


NOTE: Do Not Use META to Override HTTP Headers

You should not use <META HTTP-EQUIV...> to override server response header fields normally returned by the server. According to the HTML specifications, a browser will use the information in an HTTP header and ignore equivalent information found in a META element.


Important Uses of META

Most servers do not parse a document for META elements, although several browsers parse documents for specific META elements and their content. In particular, most Web indexing tools (Lycos, AltaVista, etc.) check for specific META elements to guide them in their indexing. The most common cases are:

1.  Specifying document character set:
<META HTTP-EQUIV=“content-type” CONTENT=“text/html; charset=“EUC-2”>

Gives the content-type of the document, as the HTTP content-type header field, but also lists the character set in which the document is written. This is useful, as most servers cannot currently indicate character set information relevant to the documents they serve out.
2.  Specify expiry time for a document:
<META HTTP-EQUIV=“expires” CONTENT=“Tue, 01 Jan 1981 01:00:00 GMT”>

Gives the expiry date for the document—a browser or server will not cache a document past its expiry date. Giving an expiry date in the past (as in the example) will hopefully prevent the document from being cached by a browser or proxy server.
3.  Special document “refresh” request:
<META HTTP-EQUIV=“refresh” CONTENT=“10; URL=“http://foo.org/bx.html”>

This widely supported extension asks the browser to wait 10 seconds, and then access the indicated URL. Chapter 11 describes this client-pull feature in more detail.
4.  Specify PICS page content-rating information:
<META HTTP-EQUIV=“PICS-Label” CONTENT=“PICS-1.0 label information”>

References a PICS (Platform for Internet Content Selection) label for the document. PICS is a rating scheme for Web pages, and provides a way of censoring content that might be unfit for young children. Some browsers understand PICS, and will refuse to display documents that are PICS-rated as unsatisfactory. PICS information is available from the references at the end of this chapter.
5.  Specify keywords for Web search engine:
<META NAME=“keywords” CONTENT=“space separated keywords list”>

Several Web-based search engines will preferentially index a document using keywords specified by META elements of this form. A careful choice of keywords can make your documents much easier to find at search engines such as Lycos, AltaVista, Yahoo!, and OpenText.
6.  Specify text description of content for Web search engine:
<META NAME=“description” CONTENT=“A short resource description”>

AltaVista indexes the content of META elements with NAME=“keywords” or NAME=“description.” The latter value is also used by the search engine as a brief description of the resource . If this is absent, AltaVista uses the first few sentences of the document.
7.  Tell Web robots not to index the page or follow links from the page:
<META NAME=“robots” CONTENT=“noindex, nofollow”>

This tells a Web robot that the robot should not index the document and that it should not explore any hypertext links going out from the document.
8.  Indicate author of page:
<META NAME=“author” CONTENT=“Author’s name”>

This encodes, within the document, the name of the author.
9.  Give name of software that created the document:
<META NAME=“Generator” NAME=“name and version of software”>

This encodes, within the document, the name of the software tool that generated the document. Many HTML editors include this META element.
10.  Indicate the default MIME type of any script programs in the document:
META NAME=“Content-script-type” CONTENT=“mime/type”>

This indicates the default scripting language for the document. This can be overridden by explicit script language declarations in a SCRIPT element.

SCRIPT Element: Include a Program Script

Usage: <SCRIPT> ... </SCRIPT>
Can Contain: script program code (characters)
Can Be Inside: HEAD,
ADDRESS, BLOCKQUOTE, BODY, CAPTION, CENTER, DD, DIV, DT, FIELDSET, FORM, Hn, LI, NOFRAMES, NOSCRIPT, P, PRE, TD, TH,
character highlighting, A, APPLET, BUTTON, IFRAME, LABEL, LEGEND, OBJECT
Attributes: CHARSET, DEFER, EVENT, FOR, LANGUAGE, SRC, TYPE, (ID, IN: Internet Explorer 4 only)

SCRIPT is used to include program scripts within an HTML document. If there is no SRC attribute, the content of the element is treated as script program code and is executed, if possible, by the browser. If SRC is present, then the resource specified by this attribute is retrieved and executed as script program code—in this case, the content of the element is ignored. Browsers that do not understand SCRIPT elements or the language in which the script is written will ignore this element and its content.

SCRIPT is usually nonempty, the content being the program script. To hide this content from browsers that do not understand SCRIPT, the actual code can be placed inside an HTML comment. This is illustrated in the following example, with the HTML comment markers shown in boldface (the dots indicate omitted code). Note that the ending comment string --> must be preceded by the string // —this is the string used by JavaScript to denote the start of a JavaScript comment.

<SCRIPT LANGUAGE=‘JavaScript’>

<!--
.
.
.function opentip() {
        str=“/comprod/news/todaystip.html”;
        tipWin = window.open(str,‘tipWin’,‘width=175,height=175’);
        window.open(str,‘tipWin’,‘width=175,height=175’);
        tipWin.opener = self;
}
.
.
// -->
</SCRIPT>

SCRIPT is allowed in the body as well as the HEAD: The HEAD portion should be used to define any functions used elsewhere in the document, while SCRIPTs in the BODY should be used to print script-generated text into the HTML document. This is described in more detail Chapter 7.

Inside the BODY, the element NOSCRIPT can contain HTML markup to use in place of the SCRIPT content, should the browser not understand SCRIPT or the scripting language.

SCRIPT can take a number of attributes. LANGUAGE indicates the language of a script placed inside a SCRIPT element—this is required as there are multiple scripting languages, and also multiple versions of each scripting language. SRC specifies the URL of a file containing a script program, and is used to include an external script into an HTML document. TYPE specifies the MIME-type of this file—HTML 4 recommends using TYPE in place of LANGUAGE, although at present only LANGUAGE is widely supported. The detailed specifications for these and other defined attributes are given below.

CHARSET=“string” (optional; valid only when SRC is specified; not currently supported) Specifies the character set used in the linked JavaScript program file. This is not supported by current browsers.
DEFER (optional; not currently supported)Indicates that the script does not affect the rendering of the document, and lets the browser defer execution of the script until the document is rendered. This is not supported by current browsers.
EVENT=“string” (optional; Internet Explorer 4 only; FOR must also be present) Indicates the event type that this script is bound to—the value of EVENT must be the name of a valid event handler, such as “onclick” or “onmouseover.” This attribute allows for SCRIPTs that are explicit handlers of specific events. For example, <SCRIPT EVENT="onclick" FOR="z23"> means that this script element is the event handler for onclick events arising from the element with ID=“z23.”
FOR=“string “ (optional; Internet Explorer 4 only; EVENT must also be present) Indicates the identity of the element to which the SCRIPT is bound as an event handler. See EVENT for further details.
ID=“string” (optional; Internet Explorer 4 only) Indicates the identity of the element to which the SCRIPT is bound as an event handler. See EVENT for further details.
IN=“string” (optional; Internet Explorer 4 only) Indicates the name of an element within which the script can apply (i.e., defines the scope for the script). For example, to restrict a script to be valid only inside a FORM, you could set IN equal to the NAME of the form.
LANGUAGE=“string” (optional) Specifies the language of the script contained within the SCRIPT element. The only commonly supported values are LANGUAGE=“JavaScript” for JavaScript and LANGUAGE=“VBScript” for Visual Basic Script. Internet Explorer supports both languages, while Netscape Navigator 3 supports only JavaScript. Navigator also supports the names “JavaScript1.1” and “JavaScript1.2,” corresponding to the JavaScript language implemented in Navigator 3 and Navigator 4, respectively.
SRC=“url” (optional) Specifies the URL of a file that contains a script. The browser should access the file and load the script as if it were included inline with the document.


TIP: SRC Not Properly Supported in Netscape 3

Using external script programs can lead to problems with early versions of Netscape or Internet Explorer. It is thus safest to develop script applications with the script firmly embedded inside the SCRIPT element and then to try moving them to an external file once the script is debugged.


TYPE=“string” (optional; not widely supported) Gives the MIME type for the script referenced by the SRC attribute. For example, an external JavaScript program from the file prog.js would be referenced by the markup:
<SCRIPT SRC=“http://scripts.ian.com/prog1.js”

        TYPE=“application/javascript”>
</SCRIPT>

Some common MIME types are text/x-javascript (JavaScript) and text/vbscript (VBScript).


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.