+ All Categories
Home > Documents > 251 Internet Applications Ahmed M. Zeki Sem – 2 2000/2001 ---------------- Chapter 8.

251 Internet Applications Ahmed M. Zeki Sem – 2 2000/2001 ---------------- Chapter 8.

Date post: 27-Mar-2015
Category:
Upload: elijah-doherty
View: 217 times
Download: 1 times
Share this document with a friend
Popular Tags:
25
/ 25 1 Internet Applications Ahmed M. Zeki Sem – 2 2000/2001 ---------------- Chapter 8
Transcript
Page 1: 251 Internet Applications Ahmed M. Zeki Sem – 2 2000/2001 ---------------- Chapter 8.

/ 251

Internet Applications

Ahmed M. Zeki

Sem – 2

2000/2001

----------------

Chapter 8

Page 2: 251 Internet Applications Ahmed M. Zeki Sem – 2 2000/2001 ---------------- Chapter 8.

/ 252

JavaScript The JavaScript language facilitates a disciplined

approach to designing computer programs that enhance Web pages.

Jscript is Microsoft's version of JavaScript-a scripting language that is standardized by the ECMA (European Computer Manufacturers Association) as ECMAScript.

JavaScript uses notations that may appear strange to nonprogrammers.

Internet Explorer contains the JavaScript Interpreter, which processes the commands in a script written in JavaScript.

Page 3: 251 Internet Applications Ahmed M. Zeki Sem – 2 2000/2001 ---------------- Chapter 8.

/ 253

Blank lines, space characters and tab characters are known as white-space characters, and are ignored by the browser. They are just used for readability and clarity.

The spacing displayed by a browser in a Web page is determined by the HTML elements used to format the page.

Often JavaScripts appear in the <HEAD> section of the HTML document, i.e. will be executed before the <BODY> of the HTML document.

Another kind will be included in the <BODY> section is called inline scripting.

Page 4: 251 Internet Applications Ahmed M. Zeki Sem – 2 2000/2001 ---------------- Chapter 8.

/ 254

The <SCRIPT> tag indicates to the browser that the text that follows is part of a script.

The LANGUAGE attribute specifies the scripting language used in the script

Both Microsoft Internet Explorer and Netscape Navigator use JavaScript as the default scripting language. Therefore, the LANGUAGE attribute can be omitted.

Page 5: 251 Internet Applications Ahmed M. Zeki Sem – 2 2000/2001 ---------------- Chapter 8.

/ 255

document.writeln(“<H1>Welcome to the Page</H1>”);

A string of characters can be contained between the double quotation (“) marks or single quotation (‘) marks.

The browser's document object represents the HTML document currently being displayed in the browser.

The document object allows a script programmer to specify HTML text to be displayed in the HTML document.

Page 6: 251 Internet Applications Ahmed M. Zeki Sem – 2 2000/2001 ---------------- Chapter 8.

/ 256

The browser contains a complete set of objects that allow script programmers to access and manipulate every element of an HTML document.

An object resides in the computer's memory and contains information used by the script.

The term object normally implies that attributes (data) and behaviors (methods) are associated with the object. The object's methods use the attributes to provide useful services to the client of the object - the script that calls the methods.

Page 7: 251 Internet Applications Ahmed M. Zeki Sem – 2 2000/2001 ---------------- Chapter 8.

/ 257

The document object's writeln method writes a line of HTML text in the HTML document being displayed.

Method writeln instructs the browser to display the string of HTML text based on the contents of the string.

The parentheses following a method name contain the arguments that the method requires to perform its task (or its action).

Page 8: 251 Internet Applications Ahmed M. Zeki Sem – 2 2000/2001 ---------------- Chapter 8.

/ 258

If the string contains HTML elements, the browser interprets these elements and renders them on the screen.

Using writeln to write a line of HTML text into the document does not necessarily write a line of text in the HTML document. The text displayed in the browser is entirely dependent on the contents of the string written, which is subsequently rendered by the browser. The browser will interpret the HTML elements as it normally does to render the final text in the document.

Page 9: 251 Internet Applications Ahmed M. Zeki Sem – 2 2000/2001 ---------------- Chapter 8.

/ 259

Every statement should end with a semicolon ; (also known as the statement terminator). Although none is required by JavaScript.

JavaScript is case sensitive. Not using the proper uppercase and lowercase letters is a syntax error.

A syntax error occurs when the interpreter cannot recognize a statement. It is a violation of the language rules.

Page 10: 251 Internet Applications Ahmed M. Zeki Sem – 2 2000/2001 ---------------- Chapter 8.

/ 2510

The interpreter normally issues an error message to help the programmer locate and fix the incorrect statement. The JavaScript interpreter in Internet Explorer reports all syntax errors by indicating in a separate popup window that a “run time error” occurred (a problem occurred while the interpreter was running the script).

Unlike writeln, document method write does not position the output cursor in the HTML document at the beginning of the next line of HTML text after writing its argument.

Page 11: 251 Internet Applications Ahmed M. Zeki Sem – 2 2000/2001 ---------------- Chapter 8.

/ 2511

Each write or writeln statement resumes writing characters where the last write or writeln stopped writing characters.

Sometimes it is useful to display information in windows called dialog boxes that "pop up" on the screen to grab the user's attention. Dialog boxes are typically used to display important messages to the user who is browsing the Web page. The browser's window object displays an alert dialog box with method alert. Method alert requires as its argument the string to display.

Page 12: 251 Internet Applications Ahmed M. Zeki Sem – 2 2000/2001 ---------------- Chapter 8.

/ 2512

The title bar of the dialog contains the string Microsoft Internet Explorer, to indicate that the browser is presenting a message to the user.

Dialog boxes display plain text, they don’t render HTML.

The alert dialog contains three lines of plain text.

Page 13: 251 Internet Applications Ahmed M. Zeki Sem – 2 2000/2001 ---------------- Chapter 8.

/ 2513

Normally the characters in a string are displayed exactly as they appear between the double quotes.

When a backslash is encountered in a string of characters, the next character is combined with the backslash to form an escape sequence.

The escape sequence \n is the newline character. It causes the cursor in the HTML document to move to the beginning of the next line in the dialog box.

Page 14: 251 Internet Applications Ahmed M. Zeki Sem – 2 2000/2001 ---------------- Chapter 8.

/ 2514

Escape Characters \n New line \t Horizontal tab \r Carriage Return, any characters

output after the carriage return overwrite the previous characters output on that line.

\\ Backslash \” Double quote. e.g. window.alert(“\”in

quotes\””);

\’ Single quote. e.g. window.alert(‘\’in quotes\’ ‘);

Page 15: 251 Internet Applications Ahmed M. Zeki Sem – 2 2000/2001 ---------------- Chapter 8.

/ 2515

\n, \t and \r do not affect HTML rendering unless they are in a PRE element (this element displays the text between its tags in a fixed-width font exactly as it is formatted between the tags).

The other escape sequences result in characters that will be displayed in plain text dialog boxes and in HTML.

Page 16: 251 Internet Applications Ahmed M. Zeki Sem – 2 2000/2001 ---------------- Chapter 8.

/ 2516

The keyword var is used to declare the names of variables. A variable is a location in the computer’s memory where a value can be stored for use by a program. Though not required, all variable should be declared with a name in a var statement before they are used in a program.

A variable name can be any valid identifier. An identifier is a series of characters consisting of letter, digits, underscores ( _ ) and dollar signs ($) that does not begin with a digit and does not contain any spaces.

Page 17: 251 Internet Applications Ahmed M. Zeki Sem – 2 2000/2001 ---------------- Chapter 8.

/ 2517

Declarations end with a semicolon (; ) and can be split over several lines with each variable in the declaration separated by a comma (a comma-separated list of variable names).

Several variables may be declared in one declaration or in multiple declarations.

Page 18: 251 Internet Applications Ahmed M. Zeki Sem – 2 2000/2001 ---------------- Chapter 8.

/ 2518

Programmers often indicate the purpose of each variable in the program by placing a JavaScript comment at the end of each line in the declaration. A single-line comment begins with the characters // and terminate at the end of the line.

Comments do not cause the browser to perform any action when the script is interpreted; rather, comments are ignored by the JavaScript interpreter.

Page 19: 251 Internet Applications Ahmed M. Zeki Sem – 2 2000/2001 ---------------- Chapter 8.

/ 2519

Multiple-line comments begin with delimiter /* and end with delimiter */. All text between the delimiters of the comment is ignored by the compiler.

The window object's prompt method displays a dialog into which the user can type a value. The first argument is a message (called a prompt) that directs the user to take a specific action. The optional second argument is the default string to display in the text field.

Page 20: 251 Internet Applications Ahmed M. Zeki Sem – 2 2000/2001 ---------------- Chapter 8.

/ 2520

A variable is assigned a value with an assignment statement using the assignment operator =. The = operator is called a binary operator because it has two operands.

Function parseInt converts its string argument to an integer.

Javascript has a version of the + operator for string concatenation that enables a string and a value of another data type (including another string) to be concatenated.

Page 21: 251 Internet Applications Ahmed M. Zeki Sem – 2 2000/2001 ---------------- Chapter 8.

/ 2521

Variable names correspond to locations in the computer's memory. Every variable has a name, a type size and a value.

When a value is placed in a memory location, this value replaces the previous value in that location when a value is read out of a memory location, the process is nondestructive.

The arithmetic operators are binary operators because they each operate on two operands.

Page 22: 251 Internet Applications Ahmed M. Zeki Sem – 2 2000/2001 ---------------- Chapter 8.

/ 2522

Operators in arithmetic expressions are applied in a precise sequence determined by the rules of operator precedence. ( ) left to right *, / or % left to right + or – left to right < <= > >= left to right = = != left to right = right to left

Parentheses may be used to force the order of evaluation of operators to occur in any sequence desired by the programmer.

Page 23: 251 Internet Applications Ahmed M. Zeki Sem – 2 2000/2001 ---------------- Chapter 8.

/ 2523

Parentheses are evaluated first. If they are nested, the expression in the innermost pair is evaluated first. If there are several pairs of parentheses “on the same level” not nested, they are evaluated left to right.

When we say operators are applied from left to right, we are referring to the associativity of the operator. Some operators associate from right to left.

Page 24: 251 Internet Applications Ahmed M. Zeki Sem – 2 2000/2001 ---------------- Chapter 8.

/ 2524

Java’s if structure allows a program to make a decision based on the truth or falsity of a condition. If the condition is met (the condition is true), the statement in the body of the if structure is executed. If the condition is not met (the condition is false), the body statement is not executed.

Conditions in if structures can be formed by using the equality operators and relational operators.

Page 25: 251 Internet Applications Ahmed M. Zeki Sem – 2 2000/2001 ---------------- Chapter 8.

/ 2525

Ex. Y = 2 * 5 * 5 + 3 * 5 + 7= 72


Recommended