Introduction to Programming the WWW I CMSC 10100-01 Summer 2003 Lecture 13.

Slides:



Advertisements
Similar presentations
Cookies, Sessions. Server Side Includes You can insert the content of one file into another file before the server executes it, with the require() function.
Advertisements

JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
1 CSC 551: Web Programming Spring 2004 client-side programming with JavaScript  scripts vs. programs  JavaScript vs. JScript vs. VBScript  common tasks.
HTML 5 and CSS 3, Illustrated Complete Unit L: Programming Web Pages with JavaScript.
The Web Warrior Guide to Web Design Technologies
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic JavaScript: Introduction to Scripting.
Tutorial 15 Working with the Event Model. XP Objectives Compare the IE and W3C event models Study how events propagate under both event models Write a.
Chapter 16 Dynamic HTML and Animation The Web Warrior Guide to Web Design Technologies.
HTML Comprehensive Concepts and Techniques Second Edition Project 8 Integrating JavaScript with HTML.
CIS101 Introduction to Computing Week 10 Spring 2004.
XP Tutorial 9 New Perspectives on JavaScript, Comprehensive1 Working with Cookies Managing Data in a Web Site Using JavaScript Cookies.
JavaScript 101 Lesson 5: Introduction to Events. Lesson Topics Event driven programming Events and event handlers The onClick event handler for hyperlinks.
Tutorial 11 Working with Operators and Expressions
JavaScript, Third Edition
Chapter 9 Introduction to the Document Object Model (DOM) JavaScript, Third Edition.
Web Development & Design Foundations with XHTML Chapter 14 Key Concepts.
XP Tutorial 8 New Perspectives on JavaScript, Comprehensive1 Working with the Event Model Creating a Drag-and-Drop Shopping Cart.
1 Introduction to Web Development. Web Basics The Web consists of computers on the Internet connected to each other in a specific way Used in all levels.
The Web Wizard’s Guide To DHTML and CSS Chapter 1 A Review of CSS1.
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.
Introduction to Programming the WWW I CMSC Summer 2003 Lecture 12.
The Web Wizard’s Guide To JavaScript Chapter 1 JavaScript Basics.
Server vs Client-side validation. JavaScript JavaScript is an object-based language. JavaScript is based on manipulating objects by modifying an object’s.
Review and Practice for Final exam. Final exam Date: December 20, 3:15 – 5:15pm Format: Two parts: First part: multiple-choice questions (15 questions.
JavaScript, Fourth Edition
Working with Cookies Managing Data in a Web Site Using JavaScript Cookies* *Check and comply with the current legislation regarding handling cookies.
WEEK 3 AND 4 USING CLIENT-SIDE SCRIPTS TO ENHANCE WEB APPLICATIONS.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 Dynamic Documents With JavaScript.
1 CLIENT-SIDE SCRIPTS. Objectives 2 Learn how to reference objects in HTML documents using the HTML DOM and dot syntax Learn how to create client-side.
The Web Wizard’s Guide To JavaScript Chapter 6 Working with Dates and Times.
The Web Wizard’s Guide To JavaScript Chapter 6 Working with Dates and Times.
Integrating JavaScript and HTML5 HTML5 & CSS 7 th Edition.
Creating an Animated Web Page
CITS1231 Web Technologies JavaScript and Document Object Model.
Section 17.1 Add an audio file using HTML Create a form using HTML Add text boxes using HTML Add radio buttons and check boxes using HTML Add a pull-down.
Chapter 8 Cookies And Security JavaScript, Third Edition.
JavaScript, Fourth Edition
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
Introduction to JavaScript 41 Introduction to Programming the WWW I CMSC Winter 2004 Lecture 17.
11 1 Cookies CGI/Perl Programming By Diane Zak Objectives In this chapter, you will: Learn the difference between temporary and persistent cookies.
Chapter 5: Windows and Frames
Introduction to Programming the WWW I CMSC Summer 2003 Lecture 7.
Dr. Qusai Abuein1 Internet & WWW How to program Chap.(6) JavaScript:Introduction to Scripting.
The Web Wizard’s Guide To JavaScript Chapter 7 Cookies: Maintaining State.
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.2 Revised by Dr. T. Tran for CSI3140.
Introduction to JavaScript Objects, Properties, Methods.
JavaScript, Fourth Edition Chapter 4 Manipulating the Browser Object Model.
JavaScript Introduction.  JavaScript is a scripting language  A scripting language is a lightweight programming language  A JavaScript can be inserted.
The Web Wizard’s Guide To DHTML and CSS Chapter 6 Understanding Events.
Introduction to Programming the WWW I CMSC Winter 2003 Lecture 12.
Event Handling. Objectives Using event handlers Simulating events Using event-related methods.
7. JavaScript Events. 2 Motto: Do you think I can listen all day to such stuff? –Lewis Carroll.
Chapter 27 Getting “Web-ified” (Web Applications) Clearly Visual Basic: Programming with Visual Basic nd Edition.
Introduction to Programming the WWW I CMSC Summer 2003 Lecture 9.
Understanding JavaScript and Coding Essentials Lesson 8.
Tutorial 11 1 JavaScript Operators and Expressions.
Dr. Ahmet Cengizhan Dirican BIL 374 Internet Technologies 6. Dynamic Documents With JavaScript.
Review and Practice for Final exam. Final exam Date: December 20, 3:15 – 5:15pm Format: Two parts: First part: multiple-choice questions (13 questions.
Chapter 10 Dynamic HTML (DHTML) JavaScript, Third Edition.
Javascript Basic Concepts Presentation By: Er. Sunny Chanday Lecturer CSE/IT RBIENT.
1 Using jQuery JavaScript & jQuery the missing manual (Second Edition)
DHTML.
Introduction to Programming the WWW I
14 A Brief Look at JavaScript and jQuery.
WEB PROGRAMMING JavaScript.
Working with the Event Model
Tutorial 6 Creating Dynamic Pages
Introduction to Programming the WWW I
The Web Wizard’s Guide To JavaScript
Presentation transcript:

Introduction to Programming the WWW I CMSC Summer 2003 Lecture 13

2 Reminder Final project presentation this Friday Each of you given 10 minutes to describe your project  1min: Topic of your project  1min: Structure of your project  4min: What you implemented to achieve the requirements? etc.  3min: Reflections: what did I learn? What are the possible improvements if given more time? etc.

3 Topics Today Working with Dates and Times Cookies Understanding Events

4 The Date Object JavaScript contains a set of core objects, including the Date object, that exist independently of any host environment such as a Web browserthe Date object To use the Date object, you first create an instance of it and then apply a method to obtain date and time information

5 Date Examples A simple clock  Using the toLocaleString() method of the Date object  Example Web page: listing6.1.htmllisting6.1.html A better clock  Obtaining the current hour, minute, and seconds and then concatenating them to create a new format  setInterval() vs. setTimeout()  Example Web page: listing6.2.htmllisting6.2.html

6 Date Examples (cont’d) Creating dynamic Greetings  Vary the information displayed according to the time or date  Making Web pages more user-friendly  Example Web page: listing6.4.htmllisting6.4.html More information about JavaScript Date Object  Check

7 Date Mathematics JavaScript’s Math object is a built-in calculator  Math methods summary: To perform math operations on information obtained from text fields, you first convert the values to numbers using the top-level parseInt() or parseFloat() function parseInt() parseFloat() Date mathematics allows you to create countdown pages to important events  See JS Chap. 6 pp

8 Topics Today Working with Dates and Times Cookies Understanding Events

9 What are Cookies? Cookies are small pieces of information stored on the visitor’s hard drive Cookies are used to maintain state Cookies are mostly harmless, but valid privacy concerns exist about the use of cookies in conjunction with invasive marketing techniques You can create as many as 20 cookies per domain

10 Creating Cookies Cookies are set when a JavaScript statement in a Web page assigns content to the cookie property of the document object. Content must include the name and value information Usually, content includes information about the domain and directory location of the page Example code:  document.cookie=“username=clara; expires=Mon, 18-Aug-03 00:00:00 GMT; path=/aw; domain=stevenestrella.com;”

11 Retrieving A Cookie When a Web page attempts to retrieve a cookie, the location of the Web page is compared to the domain and directory of the page that created the cookie. If the two locations do not match, the cookie cannot be retrieved

12 Deleting Cookies You can set an expiration date for your cookies. The form of the expiration date is always GMT You can eliminate a cookie by setting its expiration date to a date in the past

13 Public Domain Cookie Code Bill Dortch’s cookie code is widely used on the Internet and has been placed in the public domain  Source Code: mylibrary.jsmylibrary.js Several key functions defined  SetCookie()  GetCookie()  GetCookieVal()  DeleteCookie()

14 Example 1: First Cookie A simple program to store visitor’s name and favorite color information in cookies Example Web page: listing7.2.htmllisting7.2.html

15 Example 2: Storing Preferences One popular use of cookies is to store visitor preferences, such as background color and login information When a Web page retrieves information from a cookie, the page can act on that information by changing the page appearance to suit the expressed preferences of the visitor Example Web page: listing7.3.htmllisting7.3.html

16 Topics Today Working with Dates and Times Cookies Understanding Events

17 Event Topics Learn the history of Web browser event models Discover the nature of events on the Web Explore event propagation and bubbling Discover mouse events and position Use visibility techniques to create hypertext Create drag-and-drop applications Use keyboard events in Web page development

18 History of GUI programming Formerly, type in commands from keyboard (eg, DOS) 1970’s, 1980’s: Xerox research on GUI 1984: Macintosh operating system ~1990: Windows XWindows/UNIX

19 History of Web Browser Events Limited support for events in early browsers  onclick Expanded events in version 4.0 browsers Disparate event models (NN4 vs. IE4) New W3C event model

20 Events on the Web Browser creates events in response to user action Event object begins life when user acts Event object ends life when scripts stop processing it One event at a time Netscape and W3C static Event object IE4+ window.event Every event has a target

21 Events and Event Handlers Events are objects that contain information about what happened Event handlers are functions that are members of an element that respond to particular events

22 Propagation and Bubbling IE4 example  Listing6-1.html Listing6-1.html W3C example  Listing6-2.html Listing6-2.html (open in NN)

23 More on W3C Event Model Use.addEventListener() to add an event listener and specify whether the event should be handled on the way down or up /* on the way down */ document.addEventListener(“click”,foo,true); /* on the way up */ document.addEventListener(“click”,bar,false); Not widely employed

24 Tracking MouseMove Events and Mouse Position function showxy(evt){ if (window.event){ evt = window.event; } if (evt){ var pos = evt.clientX + ", " + evt.clientY; window.status=pos; } Example: Listing6-4.htmlListing6-4.html

25 Hypertext with Mouse Events Title tag for single line tool tips Hypertext for multi-line content Add event handlers to links onmouseover="doHT(event,'vitry','visible') ;” onmouseout="doHT(event,'vitry',’hidden');” First parameter passes event Second parameter passes ID Third parameter passes visibility Example: Listing6-5.htmlListing6-5.html

26 Drag-and-Drop Applications Place drag-and-drop code in library Place utility functions in library Add event handlers to div onmousedown="setDrag(event,this);" onmouseup="checkdroploc('1','0');” Drag begins on mousedown Drag ends on mouseup Script checks new position of div Simplified version Example: Listing6-6.htmlListing6-6.html

27 Keyboard Events Triggered by key down, key up Keyboard is fasted input device onload="init();” document.onkeyup = getKeyEvent; Obtains keyCode Check for letters, numbers, or space bar Swap text node value to show key typed Example: Listing6-7.htmlListing6-7.html