1 CSC160 Chapter 1: Introduction to JavaScript Chapter 2: Placing JavaScript in an HTML File.

Slides:



Advertisements
Similar presentations
Introducing JavaScript
Advertisements

JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
Java Script Session1 INTRODUCTION.
Website Design.
Introduction to JavaScript
The Web Warrior Guide to Web Design Technologies
Server-Side vs. Client-Side Scripting Languages
JavaScript 101 Lesson 01: Writing Your First JavaScript.
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
Tutorial 10 Programming with JavaScript
XP 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial 10.
XP Tutorial 1 New Perspectives on JavaScript, Comprehensive1 Introducing JavaScript Hiding Addresses from Spammers.
Tutorial 1: Introduction to JavaScript JavaScript - Introductory.
2012 •••••••••••••••••••••••••••••••••• Summer WorkShop Mostafa Badr
Inline, Internal, and External FIle
Introduction to JavaScript. Aim To enable you to write you first JavaScript.
Introduction to scripting
Javascript and the Web Whys and Hows of Javascript.
4.1 JavaScript Introduction
Lecture Note 3: ASP Syntax.  ASP Syntax  ASP Syntax ASP Code is Browser-Independent. You cannot view the ASP source code by selecting "View source"
CS346 - Javascript 1, 21 Module 1 Introduction to JavaScript CS346.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
SEG3210 DHTML Tutorial. DHTML DHTML is a combination of technologies used to create dynamic and interactive Web sites. –HTML - For creating text and image.
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
Section 17.1 Add an audio file using HTML Create a form using HTML Add text boxes using HTML Add radio buttons and check boxes using HTML Add a pull-down.
What is Java Script? An extension to HTML. An extension to HTML. Allows authors to incorporate some functionality in their web pages. (without using CGI.
Lesson13. JavaScript JavaScript is an interpreted language, designed to function within a web browser. It can also be used on the server.
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
1 JavaScript in Context. Server-Side Programming.
XP Tutorial 10New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with JavaScript Creating a Programmable Web Page for North Pole.
Tutorial 10 Programming with JavaScript. XP Objectives Learn the history of JavaScript Create a script element Understand basic JavaScript syntax Write.
Tutorial 10 Programming with JavaScript
Done by: Hanadi Muhsen1 Tutorial 1.  Learn the history of JavaScript  Create a script element  Write text to a Web page with JavaScript  Understand.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
Active Server Pages  In this chapter, you will learn:  How browsers and servers interacted on the Internet when the Internet first became popular 
JavaScript. During the last lecture We looked at the utility of forms on Web pages We found out about the various components that are used in a form We.
Introduction.  The scripting language most often used for client-side web development.  Influenced by many programming languages, easier for nonprogrammers.
7 Chapter Seven Client-side Scripts. 7 Chapter Objectives Create HTML forms Learn about client-side scripting languages Create a client-side script using.
Dr. Qusai Abuein1 Internet & WWW How to program Chap.(6) JavaScript:Introduction to Scripting.
1 JavaScript
Introduction to JavaScript CS101 Introduction to Computing.
Overview of Form and Javascript fundamentals. Brief matching exercise 1. This is the software that allows a user to access and view HTML documents 2.
Sahar Mosleh California State University San MarcosPage 1 JavaScript Basic.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
By Tharith Sriv. To write a web page you use: HHTML (HyperText Markup Language), AASP (Active Server Page), PPHP (HyperText Preprocessor), JJavaScript,
JavaScript Introduction.  JavaScript is a scripting language  A scripting language is a lightweight programming language  A JavaScript can be inserted.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Introduction into JavaScript Java 1 JavaScript JavaScript programs run from within an HTML document The statements that make up a program in an HTML.
1 JavaScript in Context. Server-Side Programming.
HTML Overview Part 5 – JavaScript 1. Scripts 2  Scripts are used to add dynamic content to a web page.  Scripts consist of a list of commands that execute.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
Chapter 1 Introduction to JavaScript JavaScript, Third Edition.
Java Script. What is JavaScript ? It is an scripting language, developed by Netscape Navigator. It can be used to replace CGI scripts for client-side.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
JavaScript and AJAX 2nd Edition Tutorial 1 Programming with JavaScript.
XP Tutorial 10New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties.
Web Programming Java Script-Introduction. What is Javascript? JavaScript is a scripting language using for the Web. JavaScript is a programming language.
Module 1 Introduction to JavaScript
Introduction to Scripting
4. Javascript Pemrograman Web I Program Studi Teknik Informatika
Introduction to JavaScript
Introduction to JavaScript
Tutorial 10 Programming with JavaScript
Tutorial 10: Programming with javascript
An Introduction to JavaScript
Introduction to Programming and JavaScript
Introduction to JavaScript
Presentation transcript:

1 CSC160 Chapter 1: Introduction to JavaScript Chapter 2: Placing JavaScript in an HTML File

2 What is JavaScript? JavaScript is a web-specific scripting language It is usually placed in an HTML file to make Web pages more interactive, and to give Web pages some special features (visual or otherwise). HTML is used to develop static Web pages. It is not Java It is object based It is a client-side language

3 JavaScript Is NOT Java JavaScript and Java are two different languages. Java is more powerful but more complex. It is a complicated programming language that can be used to program for various kinds of applications including writing web-pages. JavaScript is web scripting language used to write web pages only.

4 JavaScript Is NOT Java (cont’d) Java is a full programming language that must be compiled before a program can be executed. Compiler can find the syntax errors so that the programmer can fix the errors before running the program. JavaScript does not need to be compiled. Instead, it is a scripting language that is interpreted on-the-fly when running. The code is interpreted as it is loaded and run. The syntax error can only be caught when actually running the program.

5 Server-Side VS. Client-Side Languages Client (Web browser) Retrieve information from the client Web Server A program in server-side language Send processed information back to the client Save information on the web server Use new information to update Web pages Server-side Client (Web browser) A JavaScript Program * Code is read & run by the client. * Data results is viewed at the client Data can be validated by the JavaScript program Client-side

6 Server-Side VS. Client-Side Languages (cont’d) A server-side language The program is run on the Web server Needs to retrieve information from the Web page or the Web browser. Often allows programmers to save information on the Web server Cannot directly access some information that a client-side language can see

7 Server-Side VS. Client-Side Languages (cont’d) A client-side language Run directly through the client (for JavaScript, the client is the Web browser) The browser reads and interprets the code Can retrieve, process data and view the results locally Without extra step of retrieving information from somewhere else This can make certain tasks run more quickly Cannot save files or updates to files on a Web server Allow information to be validated before it is sent to a server-side program or script

8 Basic Text Editor and Web Browser Knowledge Some HTML editors have problems related to adding JavaScript code Use a plain text editor or an HTML editor that handles the addition of your own JavaScript code easily Some Web browsers have trouble with the newer versions of JavaScript Use Microsoft Internet Explorer version 4.0 or later Use Netscape Navigator version 4.0 or later The following table shows the versions of JavaScript that Microsoft Internet Explorer and Netscape Navigator support MS Internet Explorer VersionNetscape Navigator VersionJavaScript Version Supported 5.5 and and /1.1

9 Where Does the JavaScript Code Go? JavaScript runs in the browser by being added directly into an existing HTML document. … Put the JavaScript code between this pair of tags Place JavaScript code into either the HEAD section or BODY section of an HTML document

10 Put JavaScript in the HEAD Section of an HTML Document Scripts that do not write to the page directly, such as those that change elements or define variables, are normally placed in the HEAD section of an HTML file In this example, a window will pop up with an alert message. This is realized by the JavaScript we insert into the HEAD section of the HTML document. My Web Page. window.alert("This is an alert message written by JavaScript"); When you open this page, a window pops up with an alert message!

11 Put JavaScript in the BODY Section of an HTML Document Scripts that write something directly to the page are normally placed in the BODY section of a HTML file In this example, text “This text was written to the page by JavaScript.” will be output to the monitor screen. This is generated by JavaScript we insert into the BODY section of the HTML document. My Web Page. This text was written by HTML. document.write( " This text is written to the page by JavaScript. " );

12 JavaScript Code document.write("This text is written to the page by JavaScript."); document: object, the HTML page dot operator (.): use an object’s methods or properties write(): method, function "This text was written to the page by JavaScript.": argument of write function, input quotation marks ("): denote a string of text semicolon (;): the end of a JavaScript statement

13 HTML SCRIPT Tags Script tags ( and ) are used to tell the browser where some type of scripting language will begin and end in an HTML document Distinguish where a script begins and ends Tell the browser which scripting language will be used Define the address for an external JavaScript file JavaScript code is put here Tells the browser where script code begins Tells the browser where script code ends

14 HTML SCRIPT Tags: Identify the Scripting Language The scripting language between and could be JavaScript, VBScript, or some other scripting language. Many browsers assume that scripting code between the opening and closing SCRIPT tags will be JavaScript, but some browsers don’t. To be safe, explicitly identify the language as JavaScript by adding the language attribute with the value of “JavaScript” to the opening SCRIPT tag JavaScript code is put here Tells the browser the scripting language will be JavaScript

15 HTML SCRIPT Tags: Identify the Version Number of JavaScript If you are writing code that works only in or above a certain version of JavaScript, you can add the version number right after the word “JavaScript” in the language attribute with no space between them Specify a version if you write scripts that use options available in only the latest versions of JavaScript JavaScript code is put here The browser will execute this code only if it can handle JavaScript 1.2 or later

16 HTML SCRIPT Tags: Identify External JavaScript Files to Be Called If you wish to call an external JavaScript file, you can add a src attribute to the opening SCRIPT tag This external JavaScript file is a text file that contains nothing but JavaScript code, and it is saved with the.js file extension If the script is extremely long, using the src attribute to add the script to multiple Web pages can be much quicker than inserting the entire code on every page This method may not be supported by some browsers Tell the browser to call an external JavaScript file named “ yourfile.js ” No spaces

17 Hide JavaScript Code from Old Browsers When the web page is opened in an old browser that does not support JavaScript, the entire content of your JavaScript code can be dumped on the page as plain text To prevent that, you can place HTML comments between the opening and closing SCRIPT tags. <!-- opens the HTML comment --> closes the HTML comment // is for the JavaScript comment JavaScript knows to ignore the opening of an HTML comment, but not the closing of an HTML comment //--> can make sure that the closing HTML comments does not cause error in the script <!-- JavaScript code is put here //--> Begins the HTML comment to hide the code from older browsers Ends the HTML comment to hide the code from older browsers

18 Case Sensitivity HTML is not case sensitive You can put the entire tag in all lowercase, uppercase, or mixed case, whatever you prefer. The SCRIPT tag is an HTML tag, so it is not case sensitive. JavaScript is case sensitive For example, “DOCUMENT.Write(“Output the text”);” is not legal JavaScript code. Instead, the correct one is “document.write("Output the text");”

19 Comments in JavaScript Comments can be used to make notes in JavaScript, such as to describe what a line of code is supposed to do disable a line in the script Inserting comment on one line (//) Anything preceding the two slashes on this line is live code which will be executed Anything after the slashes on this line will be ignored // Put your comment here Any thing after the slashes on this line is ignored

20 Comments in JavaScript (cont’d) Adding multiple-line comments (/*… */) The comments can span any number of lines We can begin the comment on one line and end it on another line /* and */ must be used in pair /* is for opening the comment */ is for closing the comment /* Put your comment here */ Any thing between /* and */ is ignored.

21 Comments in JavaScript: Examples document.write("This is CSC160: "); // document.write ("Spring, 2008,"); document.write("JavaScript"); This is CSC160: JavaScript What is displayed One-line comment document.write("This is CSC160: ") /* document.write ("Spring, 2008,"); document.write("JavaScript"); */ This is CSC160: What is displayed Multiple-line comment