Use Script Element to add Javascript to HTML page

Description

The primary method of inserting JavaScript into an HTML page is via the script element.

There are six attributes for the script element:

  • async - Optional.
    Valid only for external script files.
    script should download immediately and should not prevent other actions on the page.
  • charset - Optional.
    This attribute is rarely used, because most browsers don't honor its value.
    The character set of the code specified using the src attribute.
  • defer - Optional.
    Valid only for external scripts.
    The execution can be deferred until after the document's content has been parsed and displayed.
  • language - Deprecated.
  • src - Optional.
    Indicates an external file that contains code to be executed.
  • type - Optional.
    Replaces language attribute.
    Set the MIME type of the scripting language.
    This attribute is safe to omit, as "text/javascript" is assumed when missing.

There are two ways to use the script element:

  • embed JavaScript code directly into the page
  • include JavaScript from an external file




















Home »
  Javascript »
    Javascript Introduction »




Script Element
Syntax
Data Type
Operator
Statement
Array
Primitive Wrapper Types
Function
Object-Oriented
Date
DOM
JSON
Regular Expressions