O'Reilly logo

JavaScript® 24-Hour Trainer by Jeremy McPeak

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 1. Adding JavaScript to a Web Page

When JavaScript was first introduced to web pages, Netscape needed to find some mechanism that allowed JavaScript to be added to a web page without causing adverse effects in other browsers. After much debate, it was finally settled on to incorporate the <script/> element, which was later added to the HTML specification.

THE <SCRIPT/> ELEMENT

The primary means of adding JavaScript to a web page is by using the <script/> element. This element, introduced by Netscape, became part of the HTML 3.2 specification as a placeholder for a transition to HTML 4.01, in which the element was fleshed out and given the following attributes:

  • src: Optional. Specifies an external script file to be executed.

  • type: Required. Specifies the language used in the <script/> element's contents, and a value of "text/javascript" is typically used. Even though this attribute is required by the HTML specification, all browsers assume the language is JavaScript if this attribute is omitted.

  • language: Deprecated. This attribute specifies the language used in the <script/> element's contents. This attribute is no longer used, as type has replaced it.

  • defer: Optional. A Boolean (true or false) value that tells the browser whether to wait to execute any code within the <script/> element until after the browser loads the entire HTML document.

  • charset: Optional. The character encoding of the external code file specified by the src attribute. This attribute is rarely used.

There are ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required