JavaScript Part 9 George Mason University June 23, 2010.

Slides:



Advertisements
Similar presentations
Maintaining State Between the Client and Server Internet Programming Using VBScript and JavaScript 9.
Advertisements

ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming cookies.
JavaScript Forms Form Validation Cookies. What JavaScript can do  Control document appearance and content  Control the browser  Interact with user.
Lesson 8 Cookies. What is a cookie A little “tarball” of information stored on the client machine’s hard drive. –Usually in the cookies.txt file –information.
JavaScript Forms Form Validation Cookies CGI Programs.
Web-based Application Development Lecture 20 April 4, 2006 Anita Raja.
Chapter 16 Dynamic HTML and Animation The Web Warrior Guide to Web Design Technologies.
Javascript Document Object Model. How to use JavaScript  JavaScript can be embedded into your html pages in a couple of ways  in elements in both and.
20/1/12.  Cookies are a useful way of storing information on the client’s computer  Initially feared, when they first appeared and were considered a.
XP Tutorial 9 New Perspectives on JavaScript, Comprehensive1 Working with Cookies Managing Data in a Web Site Using JavaScript Cookies.
Chapter 9 Introduction to the Document Object Model (DOM) JavaScript, Third Edition.
4.01 Cascading Style Sheets
Session 2 Tables and forms in HTML Adapted by Sophie Peter from original document by Charlie Foulkes.
Tutorial 3: Adding and Formatting Text. 2 Objectives Session 3.1 Type text into a page Copy text from a document and paste it into a page Check for spelling.
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
Course Textbook: Build Your Own ASP.Net Website: Chapter 2
1 Events Lect 8. 2 Event-driven Pages one popular feature of the Web is its interactive nature e.g., you click on buttons to make windows appear e.g.,
Client-Side programming with JavaScript 3
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Introduction to Programming the WWW I CMSC Summer 2003 Lecture 12.
CHAPTER 12 COOKIES AND SESSIONS. INTRO HTTP is a stateless technology Each page rendered by a browser is unrelated to other pages – even if they are from.
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.
Chapter 5 Java Script And Forms JavaScript, Third Edition.
Cookies and Security Saving the “state”
JavaScript, Fourth Edition
5 Chapter Five Web Servers. 5 Chapter Objectives Learn about the Microsoft Personal Web Server Software Learn how to improve Web site performance Learn.
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.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
Session 10: Managing State. Overview State Management Types of State Management Server-Side State Management Client-Side State Management The Global.asax.
CSS Class 7 Add JavaScript to your page Add event handlers Validate a form Open a new window Hide and show elements Swap images Debug JavaScript.
Week 9 PHP Cookies and Session Introduction to JavaScript.
SEG3210 DHTML Tutorial. DHTML DHTML is a combination of technologies used to create dynamic and interactive Web sites. –HTML - For creating text and image.
 This presentation introduces the following: › 3 types of CSS › CSS syntax › CSS comments › CSS and color › The box model.
Integrating JavaScript and HTML5 HTML5 & CSS 7 th Edition.
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
Database-Driven Web Sites, Second Edition1 Chapter 5 WEB SERVERS.
Chapter 8 Cookies And Security JavaScript, Third Edition.
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
Regular Expression (continue) and Cookies. Quick Review What letter values would be included for the following variable, which will be used for validation.
Chapter 6 Server-side Programming: Java Servlets
Cookies Web Browser and Server use HTTP protocol to communicate and HTTP is a stateless protocol. But for a commercial website it is required to maintain.
1 © Netskills Quality Internet Training, University of Newcastle HTML Forms © Netskills, Quality Internet Training, University of Newcastle Netskills is.
11 1 Cookies CGI/Perl Programming By Diane Zak Objectives In this chapter, you will: Learn the difference between temporary and persistent cookies.
HTML Basics BCIS 3680 Enterprise Programming. Web Client/Server Architecture 2  Your browser (the client) requests a Web page from a remote computer.
7 Chapter Seven Client-side Scripts. 7 Chapter Objectives Create HTML forms Learn about client-side scripting languages Create a client-side script using.
Forms Collecting Data CSS Class 5. Forms Create a form Add text box Add labels Add check boxes and radio buttons Build a drop-down list Group drop-down.
ECMM6018 Enterprise Networking for Electronic Commerce Tutorial 7
Persistence Maintaining state using cookies and queries.
Copyright ©2005  Department of Computer & Information Science Working with Cookies.
Cookies (continue). Extracting Data From Cookies Data retrieved from a cookie is a simple text string. While there is no specific JavaScript function.
1 CSC160 Chapter 7: Events and Event Handlers. 2 Outline Event and event handlers onClick event handler onMouseOver event handler onMouseOut event handler.
 Previous lessons have focused on client-side scripts  Programs embedded in the page’s HTML code  Can also execute scripts on the server  Server-side.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Cookies. Cookie A cookie is a method for a Web server to maintain state information about users as users navigate different pages on the site, and as.
HTML Forms.
JavaScript: Objects 1 © by Pearson Education, Inc. All Rights Reserved.
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.
Project 5: Customizing User Content Essentials for Design JavaScript Level Two Michael Brooks.
XP 1 Charles Edeki AIU Live Chat for Unit 2 ITC0381.
AJAX CS456 Fall Examples Where is AJAX used? Why do we care?
JavaScript and Ajax (JavaScript Environment) Week 6 Web site:
XP New Perspectives on Macromedia Dreamweaver MX 2004 Tutorial 5 1 Adding Shared Site Elements.
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.
JavaScript, Sixth Edition
Cookies and JavaScript
WEB PROGRAMMING JavaScript.
Cascading Style Sheets™ (CSS)
CSc 337 Lecture 25: Cookies.
Presentation transcript:

JavaScript Part 9 George Mason University June 23, 2010

Topics Cookies QueryString Menus

Cookies Cookies are a small amount of data stored by the web browser and associated with a particular web page or site Cookies are transient by default; the values go away when the user exits the browser If you want to have the cookie last longer, you need to specify the expiration date of the cookie

Cookie Duration The original way to specify cookie duration was by setting an expiration date in the future This still works, but now there is a max-age attribute which specifies the lifetime of the cookie in seconds Using either of these causes the browser to save the cookie in a file on the hard drive

Cookie Access By default, a cookie is accessible to the web page that created it, any other page in the same folder, or any subdirectories of that folder You can set the path attribute to allow access from other folders

Cookie Domain By default, cookies are only accessible to pages on the same server from which they were set Large web sites however may utilize several servers and the domain attribute can make the cookie available on multiple servers You cannot make the cookie available to another domain

Setting Cookies document.cookie = "cookieName"=cookieValue + ",expires=" + expirationDateGMT+ "; path=" + URLpath + "; domain"=siteDomain Only the initial name/value pair is required; often the cookieValue will have been entered by the user in a form -To change the value of a cookie, set its value again using the same name, path, and domain

Deleting Cookies To delete a cookie, specify a max-age attribute of 0 or use the expires attribute and specify an expiration date in the past

Reading Cookies document.cookie returns a String that contains all cookies that apply to the current document This is a set of name-value pairs, separated by semicolons and does not include any of the attributes that may have been set for the cookie You then parse this string using the String methods of indexOf(), substring(), and split()

Parsing Cookies The split() method creates an array of Strings; for example, since the name value pairs are separated by semicolons; one can get the individual cookies by the following code: allcookies = document.cookie; cookieArray = allcookies.split(";");

Query String The query string is the portion of a URL following a question mark The query string consists of a series of name=value pairs, separated by &'s The query string can be formed by submitting a form using the GET method or by creating a link with the name/value pairs embedded in the link

Query Strings and JavaScript The query string of a page can be accessed by window.location.search – this includes the ? The query string can be parsed using the same String methods and techniques used in the parsing of cookies Server-side programming languages provide methods to obtain the value for a specified name in a query string without having to rely on String methods

Menus Although we've seen that menus can be done just with CSS, more commonly they are done with a combination of JavaScript and CSS CSS properties visibility rather than display positioning – absolute rather than relative left and top text-decoration

Menus (cont.) JavaScript onmouseover and onmouseout event handlers used dynamically change CSS properties, primarily visibility

Menus #m1, #m2 {position:absolute; height: 100px; width: 200px;} #t1, #t2 {visibility:hidden; position:absolute; left:50px;} <span id="m1" onmouseover="document.getElementById('t1').style.visibility='visible'; onmouseout="document.getElementById('t1').style.visibility='hidden';"> NBA Lakers Celtics <span id="m2" onmouseover="document.getElementById('t2').style.visibility='visible';" onmouseout="document.getElementById('t2').style.visibility='hidden';> FCC NBC CBS Content