HTML scripting
Encyclopedia
The W3C
HTML
standard includes support for client-side scripting
.
It defines how locally executable script
s may be used in a web page
.
A particular client-side application, such as a web browser
, may support several script languages.
Script code may be executed as the document loads or at a later time.
Script code can be written directly in the HTML document inside:
s occur for different elements of a web-page:
Script code may be associated with an event and element by writing code in an HTML attribute. The name of the attribute must be that of a supported intrinsic event for the element (for example, "onLoad"). The script is executed whenever the event occurs for that element. These scripts are mostly JavaScript. The HTML intrinsic event model consist of the following events:
Some browsers support additional event attributes (outside the standard), such as:
supported a feature called "JavaScript entities" or "script macros" by which script code could be included in HTML attribute values, using a syntax similar to that of character entity reference
s. For example, the code
The HTML 4.01 specification reserves a syntax for the "future support of script macros" in HTML attributes, but they have not been incorporated into later standards and are not supported by any current browser.
World Wide Web Consortium
The World Wide Web Consortium is the main international standards organization for the World Wide Web .Founded and headed by Tim Berners-Lee, the consortium is made up of member organizations which maintain full-time staff for the purpose of working together in the development of standards for the...
HTML
HTML
HyperText Markup Language is the predominant markup language for web pages. HTML elements are the basic building-blocks of webpages....
standard includes support for client-side scripting
Client-side scripting
Client-side scripting generally refers to the class of computer programs on the web that are executed client-side, by the user's web browser, instead of server-side...
.
It defines how locally executable script
Scripting language
A scripting language, script language, or extension language is a programming language that allows control of one or more applications. "Scripts" are distinct from the core code of the application, as they are usually written in a different language and are often created or at least modified by the...
s may be used in a web page
Web page
A web page or webpage is a document or information resource that is suitable for the World Wide Web and can be accessed through a web browser and displayed on a monitor or mobile device. This information is usually in HTML or XHTML format, and may provide navigation to other web pages via hypertext...
.
A particular client-side application, such as a web browser
Web browser
A web browser is a software application for retrieving, presenting, and traversing information resources on the World Wide Web. An information resource is identified by a Uniform Resource Identifier and may be a web page, image, video, or other piece of content...
, may support several script languages.
Script code may be executed as the document loads or at a later time.
Script code can be written directly in the HTML document inside:
- SCRIPT elements
- Intrinsic event attributes
The SCRIPT element type
SCRIPT elements may occur zero or more times within the HEAD and BODY elements. Scripts within script elements are processed as the document loads.Intrinsic event attributes
EventEvent-driven programming
In computer programming, event-driven programming or event-based programming is a programming paradigm in which the flow of the program is determined by events—i.e., sensor outputs or user actions or messages from other programs or threads.Event-driven programming can also be defined as an...
s occur for different elements of a web-page:
- Documents (BODY and FRAMESET)
- Forms
- UIUser interfaceThe user interface, in the industrial design field of human–machine interaction, is the space where interaction between humans and machines occurs. The goal of interaction between a human and a machine at the user interface is effective operation and control of the machine, and feedback from the...
elements (Anchor, Control Element, Image)
Script code may be associated with an event and element by writing code in an HTML attribute. The name of the attribute must be that of a supported intrinsic event for the element (for example, "onLoad"). The script is executed whenever the event occurs for that element. These scripts are mostly JavaScript. The HTML intrinsic event model consist of the following events:
- Document
- onLoad
- onUnload
- Form
- onSubmit
- onReset
- Document and UI elements
- Focus
- onFocus
- onBlur
- Focus
- UI elements
- Mouse
- Movement
- onMouseOver
- onMouseOut
- onMouseMove
- Button
- onClick
- onDblClick
- onMouseDown
- onMouseUp
- Movement
- Keyboard
- onKeyPress
- onKeyDown
- onKeyUp
- Other (TEXT/TEXTAREA)
- Lost focus with modified content
- onChange (also OPTION)
- Text selection
- onSelect
- Lost focus with modified content
- Mouse
Some browsers support additional event attributes (outside the standard), such as:
- onResize
- onMove
- onScroll
- onAbort
Script macros
Netscape NavigatorNetscape Navigator
Netscape Navigator was a proprietary web browser that was popular in the 1990s. It was the flagship product of the Netscape Communications Corporation and the dominant web browser in terms of usage share, although by 2002 its usage had almost disappeared...
supported a feature called "JavaScript entities" or "script macros" by which script code could be included in HTML attribute values, using a syntax similar to that of character entity reference
Character entity reference
In the markup languages SGML, HTML, XHTML and XML, a character entity reference is a reference to a particular kind of named entity that has been predefined or explicitly declared in a Document Type Definition . The "replacement text" of the entity consists of a single character from the Universal...
s. For example, the code
<img width="&{prompt('Width?')};" src="foo.jpg">
calls the JavaScript prompt function to ask the user how wide the image should be.The HTML 4.01 specification reserves a syntax for the "future support of script macros" in HTML attributes, but they have not been incorporated into later standards and are not supported by any current browser.