Presentation is loading. Please wait.

Presentation is loading. Please wait.

Project 5: Customizing User Content Essentials for Design JavaScript Level Two Michael Brooks.

Similar presentations


Presentation on theme: "Project 5: Customizing User Content Essentials for Design JavaScript Level Two Michael Brooks."— Presentation transcript:

1 Project 5: Customizing User Content Essentials for Design JavaScript Level Two Michael Brooks

2 Copyright (c) 2005 Prentice-Hall. All rights reserved. 2 Objectives Create and access cookies Manipulate cookies Produce dynamically generated code Use escape characters and escape sequences Generate dynamic tables and pages Utilize bookmarklets

3 Copyright (c) 2005 Prentice-Hall. All rights reserved. 3 Why Would I Do This? Static documents – do not change with user choices or changing conditions Dynamic documents – respond to user choices or changing conditions  Dynamically generated HTML combines HTML and JavaScript  Cookies allow Web sites and browsers to remember user preferences

4 Copyright (c) 2005 Prentice-Hall. All rights reserved. 4 Creating and Accessing Cookies HTML is stateless –  once you leave a Web site, it doesn’t remember you were there Cookie – a small text file stored on a user’s computer  Allows a Web application to maintain a persistent state  Browser can “remember” you Can be manipulated using the document.cookie property

5 Copyright (c) 2005 Prentice-Hall. All rights reserved. 5 Understanding Headers Header – text sent to your browser before HTML content Common types of information in header  Cookies – text files stored on user’s computer  Caching – how long page should remain in your browser’s locally-stored cache  Content-encoding –the type of files being compressed and sent to the browser

6 Copyright (c) 2005 Prentice-Hall. All rights reserved. 6 Cookie Attributes Must be created in name-value pairs  “userName = Evalyne” contains the attribute and the value of that attribute Cookie may have multiple attributes  Written as a single string, separated by semi- colons

7 Copyright (c) 2005 Prentice-Hall. All rights reserved. 7 Using Cookies To write a cookie, assign a value to the cookie property of the documentwrite a cookie To read a cookie, read the document cookie propertyread a cookie

8 Copyright (c) 2005 Prentice-Hall. All rights reserved. 8 Writing a Cookie Return

9 Copyright (c) 2005 Prentice-Hall. All rights reserved. 9 Reading a Cookie Return

10 Copyright (c) 2005 Prentice-Hall. All rights reserved. 10 Manipulating Cookies Four pre-defined attributes of the cookie property can be set using JavaScript  Expires – defines how long a cookie can be used  Path – allows cookie to be read from a page in a different folder  Domain – defines which domain can read the cookie Used to maintain user privacy  Secure – determines whether cookie should only be available during a secure (https) session

11 Copyright (c) 2005 Prentice-Hall. All rights reserved. 11 Working with Multiple Attributes Split() method separates single-string value into multiple attributes Split()  Assigns each attribute to an element in an array

12 Copyright (c) 2005 Prentice-Hall. All rights reserved. 12 Using the Split() method Return

13 Copyright (c) 2005 Prentice-Hall. All rights reserved. 13 Producing Dynamically Generated Code Dynamically generated HTML – created when a scripting language generates HTML Dynamically generated HTML Dynamic HTML (DHTML) – combines JavaScript, HTML, and Cascading Style Sheets  Used for tasks such as creating pull-down menus Create pages that react to user choices or display rapidly changing information

14 Copyright (c) 2005 Prentice-Hall. All rights reserved. 14 Dynamically Generated HTML Return

15 Copyright (c) 2005 Prentice-Hall. All rights reserved. 15 Generating Dynamic Tables and Pages Populate an array Use the length property of an array to determine how many items are in the array Use the for statement to loop through all elements Use the document.write() method to generate the HTML tables Use the document.write()

16 Copyright (c) 2005 Prentice-Hall. All rights reserved. 16 Dynamically Generated Tables Return

17 Copyright (c) 2005 Prentice-Hall. All rights reserved. 17 Using Escape Characters and Sequences Escape sequences – codes you can use to represent characters that would normally create syntax errors Escape sequences  Escape character – marks beginning of an escape sequence

18 Copyright (c) 2005 Prentice-Hall. All rights reserved. 18 Common Escape Sequences \t – Tab character \n – Newline character \r – Carriage return \’ – Single quote \” – Double quote \\ - backslash

19 Copyright (c) 2005 Prentice-Hall. All rights reserved. 19 Escape Sequences Return

20 Copyright (c) 2005 Prentice-Hall. All rights reserved. 20 Utilizing Bookmarklets Bookmarklets – small chunks of JavaScript code you can use in place of URLs  Identified with the javascript keyword, followed by a colon, then a JavaScript command. Can be added to your Favorites menu.

21 Copyright (c) 2005 Prentice-Hall. All rights reserved. 21 Creating and Using Bookmarklets Create a bookmarklet Install a bookmarklet Apply a bookmarklet

22 Copyright (c) 2005 Prentice-Hall. All rights reserved. 22 Create a Bookmarklet Return

23 Copyright (c) 2005 Prentice-Hall. All rights reserved. 23 Install a Bookmarklet Return

24 Copyright (c) 2005 Prentice-Hall. All rights reserved. 24 Apply a Bookmarklet ReturnThe New Desktop

25 Copyright (c) 2005 Prentice-Hall. All rights reserved. 25 The New Desktop Return


Download ppt "Project 5: Customizing User Content Essentials for Design JavaScript Level Two Michael Brooks."

Similar presentations


Ads by Google