Presentation is loading. Please wait.

Presentation is loading. Please wait.

Creating Active Web Pages Chapter 8 Learn how to… List the primary scripting languages and describe JavaScript. Understand the purpose of the Document.

Similar presentations


Presentation on theme: "Creating Active Web Pages Chapter 8 Learn how to… List the primary scripting languages and describe JavaScript. Understand the purpose of the Document."— Presentation transcript:

1

2 Creating Active Web Pages Chapter 8

3 Learn how to… List the primary scripting languages and describe JavaScript. Understand the purpose of the Document Object Model (DOM). Use cookies. Use cascading style sheets. Use Dynamic HTML to create animated Web pages. Understand XML, XSL, XSLT, XHTML, and SMIL.

4 Introduction to Scripting

5 Scripting Scripting is the act of writing little computer programs that can enhance the appearance and functionality of a Web page.

6 Scripting Languages JavaScript runs client-side in the browser without requiring any server-side processing. Server-side scripting languages include: –VBScript and JScript –Microsoft’s Active Server Page (ASP) languages –C# (pronounced C-sharp) –Java –J# (Microsoft’s version of Java – pronounced J-sharp)

7 Where Do Scripts Go? You can put JavaScript in the head or in the body section of a Web page. Scripts can also reside in a separate file called an include file, which gets included in the page at runtime. A function is a named procedure you can call upon by name any time you need to execute the code in the function.

8 Where Do Scripts Run? Scripts run either on the client (or browser) or on the server that hosts the Web site. –JavaScript runs on the client. Use whenever the process you are handling can be accomplished by the browser without requiring any programming on the server side. –ASP scripts run on the server.

9 Hello World!

10 Code Analysis The start and stop tags mark the beginning and ending of a script on a Web page. The language attribute defines the language as JavaScript. The document object is one of the JavaScript objects. The write() method causes a string of characters to be written onscreen.

11 Variables and Strings A variable is a place in the computer’s RAM that remembers, or stores, the value of something changeable. A string is a sequence of one or more alphanumeric characters. A string variable is a place in the computer memory that remembers, or stores, the alphanumeric characters in a string.

12 Variables A numeric variable is a place in the computer memory that remembers, or stores, a number point. A floating point number has a decimal point with one or more numbers after the decimal point.

13 Variable Names A variable name is the identifier used to refer to, or call upon, a place in the computer memory that stores the value of a variable. Follow a naming convention whereby integers begin with the letter i, strings begin with the letter s, and floating point numbers begin with the letter f.

14 Operators An operator is a symbol that causes a script to perform some kind of action on a variable or value. The assignment operator assigns values to variables.

15 Example Comment statements begin with the special symbol //.

16 Code Analysis

17 Concatenating Strings To concatenate means to join strings together via the concatenation operator. –In JavaScript, the concatenation operator is the + sign.

18 Example

19 Numeric Variables

20 Displaying Strings The and tags will make the person’s age and weight appear bold. JavaScript uses the special symbol " \" to denote a quote sign inside a string. The code to display the string Santa sang "Jingle Bells" as he drove the sleigh is given below.

21 Objects and Methods An object is a self-contained entity consisting of properties and methods enabling you to do something programmatically. A method is a little computer program built into an object to enable the object to do something.

22 Properties A property is an attribute of an object that has a value. –Properties can be used to check whether a user typed in his e-mail address properly.

23 Events An event is an action that provides an opportunity to trigger a script that can use objects to inspect properties and execute methods that make things happen onscreen or keep records behind the scenes.

24 Most Common Events Mouseover Mouse click Double-click Page load

25 JavaScript Clock Project

26 Customizing Date and Time

27 Example

28 Document Object Model (DOM)

29 DOM The document object model (DOM) is the official W3C structural definition of the objects, methods, and properties that comprise documents on the World Wide Web. –Visit www.w3.org/DOM for more information.www.w3.org/DOM

30 DOM Objects

31

32 Intrinsic Events

33 Dot Notation

34 Title Bar Clock Example This script will display the current time in the title bar.

35 Title Bar Clock Example

36 Arrays An array is a named table of memory locations in which values can be stored. –Defines an array with 7 slots (0 through 6). –Assigns values to the array slots.

37 DOM Objects by Arrays When a Web page loads, the browser creates arrays for the images, forms, links, anchors, and all the other elements onscreen. As the browser encounters objects on the page, it places them into these arrays. The arrays are indexed sequentially, beginning with zero. –For example, the first image on the page goes into the images array slot 0 referred to as document.images[0] –In this example, the third button on the first form of a Web page would be referred to as document.forms[0].elements[2]

38 DOM Objects by Name Use the name and id attributes to give the element a unique identifier. –Older versions of HTML use name. –New versions of HTML use id.

39 Example The following script provides three buttons that allow users to make an image smaller or larger.

40 Alert Boxes To aid in troubleshooting, insert an alert box at the point in the script at which you want to inspect the value of the variable. An alert box is a window that a script creates by executing the alert() method of the JavaScript window object. –Insert the string of characters and variables you want displayed between the ( ) in the alert() method.

41 Inspecting a Variable The code to inspect the value of a variable using an alert box to troubleshoot is given below:

42 JavaScript Code Sources

43 Rollover Effects The following script causes the photo to change when you rollover it with the mouse:

44 Rollover Effects The following script causes the picture to change from a dimly colored photo to full color in Internet Explorer:

45 Maintaining State in Cookies

46 Cookies A cookie is a place in the computer’s memory where browsers can store information about the user. –persistent cookies are stored in small text files on the user’s hard disk. –per-session cookies are stored in RAM. Cookies can be used to keep track of what you do on Web sites – that is, to maintain state.

47 Reading and Writing Cookies

48 Code Analysis To make the cookie persistent for 1 minute:

49 Code Analysis The script stores the click counter value in a cookie called ClickCounter. The value is read into a variable called iClickCounter.

50 Code Analysis

51 Cascading Style Sheets

52 A cascading style sheet (CSS) is a set of rules that define styles to be applied to entire Web pages or individual Web page elements. –Each rule consists of a selector followed by a set of curly braces containing the style properties and their values.

53 Cascading Style Sheets

54 Types of CSS An external CSS keeps all the style definitions in a separate CSS file that you include in a Web page at runtime by using the tag to apply the style sheet to the page. An embedded CSS is a style sheet that gets copied physically into the head of the Web page and applies to the Web page as a whole. An inline CSS is a style sheet that applies to only one page element so it gets copied “inline” on the page with that element.

55 An Inline CSS

56 An Embedded CSS The embedded CSS goes into the head section of the page, and the style rules defined there apply to the whole page. Below, styles are assigned to h1 headers and paragraphs:

57 Inline and Embedded CSS

58 An External CSS Create a style sheet and save it with the.css extension: In the section, reference your CSS:

59 and Tags Use the and tags to stylize part, instead of all, of a Web page element. In this example, “yellow words” has its own style: – Notice how yellow words appear onscreen. The and tags create a new division or line break, but otherwise function just like the tag.

60 Creating a Style Class A class is a named definition of one or more styles. –Create the class by prefixing its name with a dot in the CSS file.

61 Creating a Style ID An ID is a unique style identifier intended to apply to one, and only one, Web page element onscreen.

62 Absolute Positioning Absolute positioning enables you to position page elements precisely onscreen based on x,y coordinates. –The upper-left corner of the browser window is position 0,0. –Absolute positioning allows you to position overlapping objects. The z-index can be used to tell the browser the order in which to display objects that overlap.

63 Z-index Example

64

65 Dynamic HTML

66 Dynamic HTML is a term invented by Microsoft to refer to the animated Web pages you can create using the DOM to combine HTML with style sheets and scripts that bring Web pages to life.

67 Animation Effects You can use absolute positioning to place an object anywhere on the screen. JavaScript has a timer event that allows you to vary the x,y coordinates dynamically.

68 Animation Effects Code

69 Code Analysis The start tag is programmed to fire the BeginAnimation() function when the page loads:

70 Code Analysis

71 Gradient Effects A gradient is a graphical effect created by colors fading gradually across or down the screen.

72 Dynamic Gradient Effects The code to create a gradient background for a Web page is given below: –The color is formatted #AARRGGBB, where AA is the opacity ranging from 00 (transparent) to FF (full color), RR is red, GG is green, and BB is blue.

73 Page Transitions A page transition is the style or manner in which the screen changes when the browser brings up a new document and displays it onscreen.

74 Page Transitions To set the transition effect that users will see when the page comes onscreen, insert the following in the section: To set the transition effect that users will see when the page leaves the screen:

75 Page Transitions

76 Microsoft’s Code Generator http://msdn.microsoft.com/workshop/samples/author/dhtml/ DXTidemo/DXTidemo.htm

77 XML and XHTML

78 What Is XML? XML (eXtensible Markup Language) is a simple, self-describing markup language that enables computers to read and understand the structure of different kinds of documents and to exchange data across different operating systems, software applications, and hardware configurations without requiring any human intervention. –Tags define the structure of the data. –Visit www.xml.org for more information.www.xml.org

79 XML Schema An XML schema is the structural definition of the types of elements that can appear in a document, the attributes each element may have, and the relationships among the elements. –Schema files end in XSD (XML Schema Definition).

80 Sample XML Schema

81 Encoding XML Data

82 DOCTYPE Declaration The DOCTYPE declaration identifies the schema that defines the tag structure. –If all tags precisely follow the schema, the document validates and is well formed. –If it does not validate, it is malformed.

83 XML Editor XML files are plain text and can be created and edited with Notepad. However, it is easier to use an XML editor. –Microsoft’s Visual Studio.NET is the premier suite of tools for creating Web applications.

84 XSL eXtensible Stylesheet Language (XSL) is an XML dialect that Web designers use to specify the styling, layout, and pagination of the structured content in an XML document for some targeted presentation medium, such as a Web browser, a printer, an eBook, a screen reader, or a hand-held device. –Visit www.w3.org/TR/xsl for more information.www.w3.org/TR/xsl

85 XSLT XSL Transformation (XSLT) language is an XML dialect that Web designers use to transform documents from one format into another.

86 XSLT Example

87 Loose and Strict HTML Loose structural rules means that the Web page is using structural elements in use today but that may fade in the future. –To declare a page using the loose definition: –To declare a page using the strict definition:

88 Loose and Strict XHTML XHTML is a reformulation of HTML in XML. Loose XHTML relates to the differences between XML and SGML. –To define loose XHTML: –To define strict XHTML: For more info, go to www.w3.org/TR/xhtml1www.w3.org/TR/xhtml1

89 XML Module and SMIL An XML module is a collection of semantically- related XML elements and attributes oriented toward accomplishing a certain task or function. Synchronized Multimedia Implementation Language (SMIL) is an XML-based language that was created by the W3C for enabling developers to include multimedia events in Web documents.

90 XHTML+SMIL XHTML+SMIL permits the Web designer to use SMIL animations, timings, and transitions within a conventional HTML or CSS page layout. –HTML+TIME is Microsoft’s implementation that works with IE versions 5.5 and later.

91


Download ppt "Creating Active Web Pages Chapter 8 Learn how to… List the primary scripting languages and describe JavaScript. Understand the purpose of the Document."

Similar presentations


Ads by Google