Docsity

Separating Content, Presentation and Behavior in Web Development - Prof. Nelson Padua-Pere, Study notes of Computer Science

Partial preview of the text

Download Separating Content, Presentation and Behavior in Web Development - Prof. Nelson Padua-Pere and more Study notes Computer Science in PDF only on Docsity!

ANNOUNCEMENTS

 Midterm

SEPARATING CONTENT FROM BEHAVIOR

 Keep each of the following separate

 Content (HTML)

 Presentation (CSS)

 Behavior (JavaScript)

 Separating HTML and JavaScript

 Use src attribute of in

 Example: Separate folder

USE OF JAVASCRIPT IN WEB PAGES

 Unobtrusive JavaScript - programming paradigm specifying that JavaScript should not intrude on users accessing a web page, on HTML content, or CSS Stylesheets.

 Goals

 Keep JavaScript code separate from HTML  Scripts are enhancements to HTML content but the content should be available without JavaScript

 You should design web pages so they operate even if JavaScript is disabled.

 The tag can be used to define content where scripting cannot be used (e.g., disabled by user)

 Example: Separate folder

 Run example with JavaScript Disabled  ToolsOptionsContent (in Firefox)

TYPEOF OPERATOR

 Syntax:

typeof operand

typeof ( operand)

 Semantics:

Returns a string indicating the type of the operand.

 Example: TypeOf.html

 null – What is null?

 Example: Null.html

PARSING STRINGS INTO NUMBERS

 Number - Returns NaN is the argument does not represent a well-

formed numeric literal; otherwise a number.

 parseFloat – Takes a string as an argument and converts the

string to a floating point number. It stops parsing the string once it founds a character that cannot be part of a floating point number. Returns NaN if a number cannot be generated. Leading and trailing spaces are allowed.

 parseInt – Takes two parameters: a string and a radix (defaults to

10). With a string parameter behaves basically like parseFloat but returning an integer.

 Example: ParsingStrNum.html