JavaScript - Use in Web Pages

Use in Web Pages

See also: JavaScript engine and Ajax (programming)

The most common use of JavaScript is to write functions that are embedded in or included from HTML pages and that interact with the Document Object Model (DOM) of the page. Some simple examples of this usage are:

  • Loading new page content or submitting data to the server via AJAX without reloading the page (for example, a social network might allow the user to post status updates without leaving the page)
  • Animation of page elements, fading them in and out, resizing them, moving them, etc.
  • Interactive content, for example games, and playing audio and video
  • Validating input values of a web form to make sure that they are acceptable before being submitted to the server.
  • Transmitting information about the user's reading habits and browsing activities to various websites. Web pages frequently do this for web analytics, ad tracking, personalization or other purposes.

Because JavaScript code can run locally in a user's browser (rather than on a remote server), the browser can respond to user actions quickly, making an application more responsive. Furthermore, JavaScript code can detect user actions which HTML alone cannot, such as individual keystrokes. Applications such as Gmail take advantage of this: much of the user-interface logic is written in JavaScript, and JavaScript dispatches requests for information (such as the content of an e-mail message) to the server. The wider trend of Ajax programming similarly exploits this strength.

A JavaScript engine (also known as JavaScript interpreter or JavaScript implementation) is an interpreter that interprets JavaScript source code and executes the script accordingly. The first JavaScript engine was created by Brendan Eich at Netscape Communications Corporation, for the Netscape Navigator web browser. The engine, code-named SpiderMonkey, is implemented in C. It has since been updated (in JavaScript 1.5) to conform to ECMA-262 Edition 3. The Rhino engine, created primarily by Norris Boyd (formerly of Netscape; now at Google) is a JavaScript implementation in Java. Rhino, like SpiderMonkey, is ECMA-262 Edition 3 compliant.

A web browser is by far the most common host environment for JavaScript. Web browsers typically create "host objects" to represent the Document Object Model (DOM) in JavaScript. The web server is another common host environment. A JavaScript webserver would typically expose host objects representing HTTP request and response objects, which a JavaScript program could then interrogate and manipulate to dynamically generate web pages.

Because JavaScript is the only language that the most popular browsers share support for, it has become a target language for many frameworks in other languages, even though JavaScript was never intended to be such a language. Despite the performance limitations inherent to its dynamic nature, the increasing speed of JavaScript engines has made the language a surprisingly feasible compilation target.

Read more about this topic:  JavaScript

Other articles related to "use in web pages, web, page":

JavaScript - Use in Web Pages - Accessibility
... has not disabled its execution, client-side web JavaScript should be written to enhance the experiences of visitors with visual or physical disabilities, and certainly should ... and so may access and read the page DOM after the script has altered it ... JavaScript should not be used in a way that is confusing or disorienting to any web user ...

Famous quotes containing the words pages and/or web:

    Mathematics may be compared to a mill of exquisite workmanship, which grinds your stuff of any degree of fineness; but nevertheless, what you get out depends upon what you put in; and as the grandest mill in the world will not extract wheat- flour from peascods, so pages of formulae will not get a definite result out of loose data.
    Thomas Henry Huxley (1825–95)

    These seem like bristles, and the hide is tough.
    No claw or web here: each foot ends in hoof.
    Thom Gunn (b. 1929)