HTML scripting

HTML

* Dynamic HTML
* HTML5
* audio
* canvas
* video
* XHTML
* Basic
* Mobile Profile
* C-HTML
* HTML element
* span and div
* HTML attribute
* HTML frame
* HTML editor
* Character encodings
* Unicode
* Language code
* Document Object Model
* Browser Object Model
* Style sheets
* CSS
* Font family
* Web colors
* HTML scripting
* JavaScript
* WebGL
* WebCL
* W3C
* Validator
* WHATWG
* Quirks mode
* Web storage
* Rendering engine

Comparisons

* Document markup languages
* HTML support
* XHTML
* 1.1

The W3C HTML standard includes support for client-side scripting. It defines how locally executable scripts 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:

* SCRIPT elements
* Intrinsic event attributes

## Contents

* 1 Script macros
* 1.1 Intrinsic event attributes
* 1.2 Script macros
* 2 References

## Script macros

### Intrinsic event attributes

Events occur for different elements of a web-page:

* Documents (BODY and FRAMESET)
* Forms
* UI 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:[1]

* Document
* onUnload
* Form
* onSubmit
* onReset
* Document and UI elements
* Focus
* onFocus
* onBlur
* UI elements
* Mouse
* Movement
* onMouseOver
* onMouseOut
* onMouseMove
* Button
* onClick
* onDblClick
* onMouseDown
* onMouseUp
* Keyboard
* onKeyPress
* onKeyDown
* onKeyUp
* Other (TEXT/TEXTAREA)
* Lost focus with modified content
* onChange (also OPTION)
* Text selection
* onSelect

Some browsers support additional event attributes (outside the standard), such as:

* onResize
* onMove
* onScroll
* onAbort

### Script macros

Netscape Navigator 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 references. 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.[2]

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. A polyfill (entities.js) has been created in order to allow "script macros" in browsers that do not natively support this feature.

## References

1. ↑ "Scripts in HTML documents". W3C. http://www.w3.org/TR/html4/interact/scripts.html#h-18.2.3. Retrieved 21 August 2012.
2. ↑ David Flanagan (19 November 2001). JavaScript: The Definitive Guide: The Definitive Guide, 4th Edition. O'Reilly Media, Inc.. pp. 192–. ISBN 978-0-596-00048-6. https://books.google.com/books?id=vJGlu9t9LNYC&pg=PA192. Retrieved 21 August 2012.

0.00

(0 votes)

|

Retrieved from "https://handwiki.org/wiki/index.php?title=HTML_scripting&oldid=238226"