Web Programming 03
Web Programming 03
CS333-CS644
Dr Safa’a Saleh
1
Lecture 3
JavaScript
Scripting language which is used to enhance the functionality
and appearance of web pages.
Before you can run code examples with JavaScript on
your computer, you may need to change your browser’s
security settings.
IE9 prevents scripts on the local computer from running by
default
Firefox, Chrome, Opera, Safari (including on the iPhone) and
the Android browser have JavaScript enabled by default.
We begin with a simple script that displays the text
"Welcome to JavaScript Programming!" in the
HTML5 document.
All major web browsers contain JavaScript interpreters,
which process the commands written in JavaScript.
Spacing displayed by a browser in a web page is determined
by the HTML5 elements used to format the page
Often, JavaScripts appear in the <head> section of the
HTML5 document
The browser interprets the contents of the <head> section
first
The <script> tag indicates to the browser that the text that
follows is part of a script.
Attribute type specifies the scripting language used in the
script—such as text/javascript
The script Element and Commenting Your Scripts
The <script> tag indicates to the browser that the text
which follows is part of a script.
The type attribute specifies the MIME type of the script as
well as the scripting language used in the script—in this
case, a text file written in javascript.
In HTML5, the default MIME type for a <script> is
"text/html", so you can omit the type attribute from
your <script> tags.
You’ll see it in legacy HTML documents with embedded
JavaScripts.
A string of characters can be contained between double
quotation (") marks (also called a string literal)
Browser’s document object represents the HTML5
document currently being displayed in the browser
Allows a you to specify HTML5 text to be displayed in the
HTML5 document
Browser contains a complete set of objects that allow
script programmers to access and manipulate every
element of an HTML5 document
Object
Resides in the computer’s memory and contains information
used by the script
The term object normally implies that attributes (data) and
behaviors (methods) are associated with the object
An object’s methods use the attributes’ data to perform useful
actions for the client of the object—the script that calls the
methods
The parentheses following the name of a method
contain the arguments that the method requires to
perform its task (or its action)
Every statement should end with a semicolon (also
known as the statement terminator), although none is
required by JavaScript
JavaScript is case sensitive
Not using the proper uppercase and lowercase letters is a
syntax error
The document object’s writeln method
Writes a line of HTML5 text in the HTML5 document
Does not guarantee that a corresponding line of text will
appear in the HTML5 document.
Text displayed is dependent on the contents of the string
written, which is subsequently rendered by the browser.
A Note About Embedding JavaScript Code into HTML5
Documents
JavaScript code is typically placed in a separate file,
then included in the HTML5 document that uses the
script.