Introduction to Web Site Development Department of Computer Science California State University, Los Angeles Lecture 9: JavaScript.

Slides:



Advertisements
Similar presentations
HTML Overview - Cascading Style Sheets (CSS). Before We Begin Make a copy of one of your HTML file you have previously created Make a copy of one of your.
Advertisements

JavaScript Part 6. Calling JavaScript functions on an event JavaScript doesn’t have a main function like other programming languages but we can imitate.
Introduction to JavaScript Module 1 Client Side JS Programming M-GO Sponsored By
The Web Warrior Guide to Web Design Technologies
Introduction to Web Site Development Steven Emory Department of Computer Science California State University, Los Angeles Lecture 4: Tables and Frames.
Introduction to Web Site Development Steven Emory Department of Computer Science California State University, Los Angeles Lecture 3: Hyperlinks and Images.
Introduction to Web Site Development Steven Emory Department of Computer Science California State University, Los Angeles Lecture 8: JavaScript I.
Introduction to Web Site Development Steven Emory Department of Computer Science California State University, Los Angeles Lecture 9: JavaScript II.
Chapter 9 Introduction to the Document Object Model (DOM) JavaScript, Third Edition.
(CS1301) Introduction to Computer Programming City Univ of HK / Dept of CS / Helena Wong 1. Overview of Programming and JavaScript - 1
Inline, Internal, and External FIle
Introduction to scripting
Web Programming – Java Script Association of Computing Activities Computer Science and Engineering Indian Institute of Technology Kanpur.
Javascript and the Web Whys and Hows of Javascript.
DHTML. What is DHTML?  DHTML is the combination of several built-in browser features in fourth generation browsers that enable a web page to be more.
4.1 JavaScript Introduction
SEG3210 DHTML Tutorial. DHTML DHTML is a combination of technologies used to create dynamic and interactive Web sites. –HTML - For creating text and image.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
DOM and JavaScript Aryo Pinandito.
DHTML: Dynamic HTML Internet Technology1. What is DHTML? A collection of enhancements to HTML ► To create dynamic and interactive websites Combination.
Images (1) Three most popular formats – Graphics Interchange Format (GIF) – Joint Photographic Experts Group (JPEG) – Portable Network Graphics (PNG) –
CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad GM-IT CIIT Islamabad CIIT Virtual Campus, CIIT COMSATS Institute.
SEG3210 DHTML Tutorial. DHTML DHTML is a combination of technologies used to create dynamic and interactive Web sites. –HTML - For creating text and image.
CITS1231 Web Technologies JavaScript and Document Object Model.
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
Javascript. Outline Introduction Fundamental of JavaScript Javascript events management DOM and Dynamic HTML (DHTML)
Introduction to Applets CS 3505 Client Side Scripting with applets.
Lesson13. JavaScript JavaScript is an interpreted language, designed to function within a web browser. It can also be used on the server.
JavaScript, Fourth Edition
Copyright 2007, Information Builders. Slide 1 Understanding Basic HTML Amanda Regan Technical Director June, 2008.
DHTML: Working with Objects Creating a Dynamic Web Page.
USING XML AS A DATA SOURCE. Data binding is a process by which information in a data source is stored as an object in computer memory. In this presentation,
Introduction to the Document Object Model DOM *Understand document structure manipulation *Dynamic effects in web pages *Programming, scripting, web content.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Client-side & Server-side Scripting ©Richard L. Goldman August 5, 2003 Requires PowerPoint 2002 or later for full functionality.
JavaScript Introduction.  JavaScript is a scripting language  A scripting language is a lightweight programming language  A JavaScript can be inserted.
HTML JAVASCRIPT. CONTENTS Javascript Example NOSCRIPT Tag Advantages Summary Exercise.
JavaScript Introduction. Slide 2 Lecture Overview JavaScript background The purpose of JavaScript A first JavaScript example Introduction to getElementById.
Introduction to HTML. _______________________________________________________________________________________________________________ 2 Outline Key issues.
 Web pages originally static  Page is delivered exactly as stored on server  Same information displayed for all users, from all contexts  Dynamic.
Introduction to Web Site Development John Hurley Department of Computer Science California State University, Los Angeles Lecture 4: Favicons Tables and.
Javascript Overview. What is Javascript? May be one of the most popular programming languages ever Runs in the browser, not on the server All modern browsers.
Web Programming Overview. Introduction HTML is limited - it cannot manipulate data How Web pages are extended (include): –Java: an object-oriented programming.
JavaScript. JavaScript Introduction JavaScript is the world's most popular programming language. It is the language for HTML and the web, for servers,
Department of Computer Science, Florida State University CGS 3066: Web Programming and Design Spring
Introduction to JavaScript MIS 3502, Spring 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 2/2/2016.
Department of Computer Science, Florida State University CGS 3066: Web Programming and Design Spring
CGS 3066: Web Programming and Design Spring 2016 Introduction to JavaScript.
JavaScript and Ajax (JavaScript Environment) Week 6 Web site:
HTML Tutorial. What is HTML HTML is a markup language for describing web documents (web pages) HTML documents are described by HTML tags Each HTML tag.
Tarik Booker CS 120 California State University, Los Angeles.
Introduction to JavaScript MIS 3502, Fall 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 9/29/2016.
CGS 3066: Web Programming and Design Spring 2017
DHTML.
Week 3: Introduction to Javascript
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Week 4: Introduction to Javascript
Intro to JavaScript CS 1150 Spring 2017.
4. Javascript Pemrograman Web I Program Studi Teknik Informatika
Introduction to JavaScript
JavaScript Introduction
JavaScript an introduction.
DHTML Javascript Internet Technology.
A second look at JavaScript
DHTML Javascript Internet Technology.
JavaScript Overview By Kevin Harville.
Introduction to JavaScript
Week 5: Recap and Portfolio Site
Web Programming and Design
Presentation transcript:

Introduction to Web Site Development Department of Computer Science California State University, Los Angeles Lecture 9: JavaScript

Why JavaScript? HTML Data What data do you want to display? CSS Presentation How is the HTML data presented? JavaScript Behavior How does the web page behave?

What is JavaScript? JavaScript is a C++-like scripting language Invented by Netscape Corporation Standardized as ECMAScript Has nothing to do with Java Can also be a programming language Microsoft's implementation of JavaScript, JScript, is also a programming language JavaScript is a trademarked name Inventor still works for Mozilla Mozilla has the most complete JavaScript implementation

The Document Object Model The document object model (DOM) is a model (a programming interface) that gives you access to the objects in your document so that you can manipulate and query them The HTML5 specification contains information about the HTML5 DOM, a model that gives you access to the elements in your HTML5 document so that you can manipulate them Different documents typically have their own DOM (Excel, Word, XML, HTML5, etc.)

JavaScript and the DOM Using JavaScript and the HTML5 DOM, you can manipulate the attributes and content of most elements in an HTML5 document JavaScript is written as a collection of statements and functions Each statement should be terminated by a semicolon (not required if new statements are put on a new line)

Dynamic HTML (DHTML) When a web page contains HTML, CSS, and JavaScript that queries the HTML5 DOM, it is oftentimes called a Dynamic HTML page (DHTML)

A Few Notes About DHTML DHTML can be used to manipulate the contents and attributes of all HTML elements in an HTML document These changes are only temporary Changes are done in memory Changes do not affect the original HTML file Refresh your web browser and you should return to the original, unmodified HTML document (unless the browser plays caching tricks)

The SCRIPT Element Description Specifies code written in a scripting language such as JavaScript, JScript or VBScript Requirements Start Tag: REQUIRED End Tag: REQUIRED Usage Usage: Anywhere in the HEAD or BODY Content Model: Scripting code.

The SCRIPT Element Common Attributes TYPE: Specifies the language of the script or format of the data; must be a valid MIME type, typically either "text/javascript" or "text/vbscript" and by default, is "text/javascript" SRC: Specifies the URL of an external script file; if this attribute is specified, the SCRIPT element must contain NO CONTENT

Hello JavaScript! document.write("Hello World");

Types of JavaScript Inline JavaScript JavaScript appears within an attribute of an HTML element, similar to inline CSS Internal JavaScript JavaScript appears within a SCRIPT element inside an HTML document (HEAD and BODY only) External JavaScript JavaScript appears outside in an external file, typically using a.JS filename extension

Internal JavaScript Use SCRIPT element without SRC attribute SCRIPT element must define content JavaScript code is the content of the SCRIPT element Example: document.write("Hello World");

External JavaScript Use SCRIPT element with SRC attribute defined SCRIPT element must not define any content SCRIPT element must still use an end tag JavaScript code goes inside an external file Example (simple external):

Inline JavaScript JavaScript code is written directly within certain HTML element attributes (such as event attributes) Example

JavaScript Variables JavaScript is a programming language, and as in other computer programming languages, you can create variables Use the var keyword to create variables Example [04] variables.html

JavaScript Functions Use functions when you want to execute code when called rather than automatically Use the function keyword to create functions The syntax is: function name_of_function(arguments) { // JavaScript code goes here } Example:

JavaScript Interfaces Window HTMLDocument HTMLElement HTMLElement Derived Interfaces

Window Attributes window.document window.location Functions window.alert(string) window.confirm(string) window.prompt(message, default) window.showModalDialog(url) window.open(url, name)

HTMLDocument Attributes document.title document.URL document.getElementById There are more but none that are so important Functions document.write(string) document.writeln(string) There are more but none that are so important

Manipulating HTML Elements To manipulate an HTML element: Give that element a unique identifier (id) Use document.getElementById(id) to get a var handle to that element Now use the HTML DOM and the var handle to access that element’s attributes and functions! Example var element = document.getElementById("myP"); element.innerHTML = "New paragraph content!";

Manipulating HTML Elements After you get a var handle to an element: element.innerHTML represents the content (stuff between the start tag and the end tag) element.attribute_name represents any attribute of that element (see example) Example var element = document.getElementById("myA"); element.href = "

HTMLElement All HTMLElements support the following Attributes innerHTML title Functions Nothing important for now

HTMLElement Derived Interfaces Many HTML elements have unique attributes and functions TABLETABLE element

HTMLTableElement Attributes innerHTML and all attributes from HTMLElement caption rows Functions insertRow(index) deleteRow(index)

HTMLImageElement Attributes alt src useMap, isMap width, height complete Functions none

HTML Events All HTML elements have event attributes See the DOM section: ents.htm Most events are pretty obvious with what they do Attributes They all start with on; onclick, onkeydown, etc. Examples