an introduction to javascript summarized from chapter 6 of “web programming: building internet...

15
An Introduction to JavaScript Summarized from Chapter 6 of “Web Programming: Building Internet Applications”, 3 rd Edition

Upload: jewel-flynn

Post on 13-Jan-2016

212 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: An Introduction to JavaScript Summarized from Chapter 6 of “Web Programming: Building Internet Applications”, 3 rd Edition

An Introduction to JavaScript

Summarized from Chapter 6 of

“Web Programming:

Building Internet Applications”, 3rd Edition

Page 2: An Introduction to JavaScript Summarized from Chapter 6 of “Web Programming: Building Internet Applications”, 3 rd Edition

What is JavaScript?

a dynamic, client-side scripting language it is not compiled it is not Java (from Sun)

developed by Netscape originally called LiveScript When Java became popular – Netscape changed

the name to JavaScript open language (no purchasing)

Page 3: An Introduction to JavaScript Summarized from Chapter 6 of “Web Programming: Building Internet Applications”, 3 rd Edition

What is JavaScript? (cont.)

Now managed by ECMA (European Computer Manufacturers Association) and adopted by ISO

Since it is a client-side language, it works with a browser

Page 4: An Introduction to JavaScript Summarized from Chapter 6 of “Web Programming: Building Internet Applications”, 3 rd Edition

What is JavaScript? (cont.)

Pros form validation (before

sending to a server) calculations create custom HTML on-

the-fly test for plug-ins and other

browser settings (does not work in IE after version 5.0; that function is now handled by ActiveX)

Cons cannot read local files

(files on the client machine)

cannot write local file (except for cookies)

cannot read/write server files

can only close it’s own windows

can only read data from it’s own pages

Page 5: An Introduction to JavaScript Summarized from Chapter 6 of “Web Programming: Building Internet Applications”, 3 rd Edition

JavaScript is Object-Oriented (?) Objects are things

In the world (cat, chair, car, etc.) In browsers (window, button, title, etc.)

Objects have properties size, color, and position are all properties Object are said to “have a” property

Object have methods (or functions) these are things that object do click(), open(), selected() are methods

Think of Think of properties as properties as being nounsbeing nouns

Think of Think of methods are methods are being verbsbeing verbs

Page 6: An Introduction to JavaScript Summarized from Chapter 6 of “Web Programming: Building Internet Applications”, 3 rd Edition

What is the DOM?

Document Object Model Developed by W3C but implemented differently in

every browser. “The Document Object Model is a platform- and

language-neutral interface that will allow programs and scripts to dynamically access and update the content, structure and style of documents. The document can be further processed and the results of that processing can be incorporated back into the presented page. This is an overview of DOM-related materials here at W3C and around the web.” (http://www.w3.org/DOM/)

objectobject

propertiesproperties

methodsmethods

Page 7: An Introduction to JavaScript Summarized from Chapter 6 of “Web Programming: Building Internet Applications”, 3 rd Edition

A Document Tree (node tree)

downloaded from http://www.w3schools.com/htmldom/default.asp

Page 8: An Introduction to JavaScript Summarized from Chapter 6 of “Web Programming: Building Internet Applications”, 3 rd Edition

A Worked Example

<html>

<head> <body>

<title> <p>

texttext

“My Page”“This is text on my

page”

<html>

<head>

<title>My Page</title>

</head>

<body>

<p>This is text on my page</p>

</body>

</html>

Page 9: An Introduction to JavaScript Summarized from Chapter 6 of “Web Programming: Building Internet Applications”, 3 rd Edition

Hello, world!

Page 10: An Introduction to JavaScript Summarized from Chapter 6 of “Web Programming: Building Internet Applications”, 3 rd Edition

Another couple of examples

Page 11: An Introduction to JavaScript Summarized from Chapter 6 of “Web Programming: Building Internet Applications”, 3 rd Edition

Conditions (if statements)

In order to validate to In order to validate to XHTML-Strict, you need to XHTML-Strict, you need to

leave out leave out ‘language=“javascript”.‘language=“javascript”.

TRUE partTRUE part

FALSE partFALSE part

Page 12: An Introduction to JavaScript Summarized from Chapter 6 of “Web Programming: Building Internet Applications”, 3 rd Edition

Example 6.3.1 A Simple Script (from text) navigator refers to navigator refers to

the browser objectthe browser object

alert creates a pop-up alert creates a pop-up windowwindow

document.write creates document.write creates the content on a web the content on a web

pagepage

onLoad and onUnload onLoad and onUnload are eventsare events

Page 13: An Introduction to JavaScript Summarized from Chapter 6 of “Web Programming: Building Internet Applications”, 3 rd Edition

A Simple Script variation

Inside the describe() function, change the document.write lines to display all of the data on a page instead of a pop-up

Page 14: An Introduction to JavaScript Summarized from Chapter 6 of “Web Programming: Building Internet Applications”, 3 rd Edition

User InputPrompt the user and Prompt the user and store the input as a store the input as a

variablevariable

You can include this in You can include this in your page to notify the your page to notify the

user that their user that their JavaScript is disabled.JavaScript is disabled.

Page 15: An Introduction to JavaScript Summarized from Chapter 6 of “Web Programming: Building Internet Applications”, 3 rd Edition