Lecture Slides for Java Script | CMSC 102, Study notes of Computer Science

Material Type: Notes; Class: INTRO INFO TECHNOLOGY; Subject: Computer Science; University: University of Maryland; Term: Unknown 1989;

Typology: Study notes

Pre 2010

Uploaded on 02/13/2009

koofers-user-ez3
koofers-user-ez3 🇺🇸

10 documents

1 / 15

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
JavaScript
JavaScript – programming language that can
appear in html pages.
It allow us to:
To dynamically create web pages
To control a browser application
Open and create new browser windows
Download and display contents of any URL
To interact with the user
Ability to interact with HTML forms
You can process values provided by checkbox, text, textarea
buttons
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Lecture Slides for Java Script | CMSC 102 and more Study notes Computer Science in PDF only on Docsity!

JavaScript ^ JavaScript – programming language that canappear in html pages. ^ It allow us to:^ ^ To dynamically create web pages^ ^ To control a browser application^ 

Open and create new browser windows  Download and display contents of any URL  To interact with the user  Ability to interact with HTML forms  You can process values provided by checkbox, text, textareabuttons

JavaScript ^ What is not possible with JavaScript^ ^ It is not possible to read and write files (security reasons)^ ^ The only networking support it provides is:^ 

It can send the contents of forms to a server and e-mailaddresses  It can cause the browser to load a web page ^ JavaScript is not Java, however …^ ^ JavaScript program constructs are similar to Java’sconstructs (in many cases identical)^ ^ JavaScript can interact with java programs

JavaScript ^ When learning JavaScript we can identify two main areas^ ^ Core JavaScript – Set of rules specifying how to write JavaScriptprograms^ ^ Client-Side JavaScript – How JavaScript is used in web browsers ^ A JavaScript program can appear^ ^ In a file by itself in a file typically with the extension

.js

^ In html files between a tags  Example1 ^ We use document.writeln to create the page contents ^ Notice the html tags present in the writeln

Embedding JavaScript in HTML ^ Different ways to embed JavaScript in HTML^ ^ By using tags in the html document^ ^ From an external file (specified via URL) using the srcattribute of the script tag^ ^

 script src behaves as if contents of file appears directlybetween the tags  As event handler  Example

(See Example2.html)

^ JavaScript URLs^ ^ javascript:alert(“Welcome”)

)

^ JavaScript is not the only language out there^ ^ Visual Basic Scripting Language (language = “VBScript”) ^ IE and Netscape will assume JavaScript if language is not specified. ^ The^ language

attribute allows you to specify a JavaScript version to use (e.g.,

External File Embedding  Script src behaves as if contents of file appears directlybetween the tags  Example

(See Example3.html and footer.js) ^ The src specifies an URL as its value ^ Advantages of external file^ ^ Simplifies html files by removing code file^ ^ Allows you to share code among html files^ ^ Improves efficiency by allowing the web browser tocache the code

Execution of JavaScript Programs^ ^ HTML parser – Takes care of processing an htmldocument^ ^ JavaScript interpreter – Takes care of processingJavaScript code^ ^ HTML parser – must stop processing an html file whenJavaScript code is found (JavaScript interpreter will thenbe running)^ ^ This implies a page with JavaScript code that is computationallyintensive can take a long time to load

JavaScript ^ Let’s go over several basic constructs that allow us to defineJavaScript programs. ^ Some definitions^ ^ string – Any set of characters in double quotes (“ “)^ ^ function/method – An entity that completes a particular task forus. It can takes values necessary to complete the particular taskand it can return values. ^ Generating Output with the document.writeln method^ ^ Allow us to add text to the html file (see Example1) by providingthe required text in “ “^ ^ You can specify html code and results of JavaScript constructs

JavaScript (Variables ) ^ variable – A memory location that can store a value. In JavaScriptvariables are declared using

var

var name;  Variables names must start with a letter and can be followed byletters and digits  A variable can hold different type of values  Values we can assign to variables  Integer – 0, 10, 40, 6, -7  Floating-point – 3.2, .67, 1.48E-20  String literals – “hello”, “goodbye”  Operators  Typical arithmetic operators (+, -, *, /)  Example 5

(See Example5.html)

JavaScript (Dialog Boxes) ^ We can perform input and output via dialog boxes ^ Input via

prompt, Example 6

(See Example6.html)

^ Notice we can define several variables at the sametime  Comments ^ Can be defined using // (Everything until end of theline is a comment) ^ Can be defined using /* / (Everything in between /and / is considered a comment. ^ / */ can span several lines (// don’t)