School of Computing and Information Systems CS 371 Web Application Programming Client-side.

Slides:



Advertisements
Similar presentations
JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
Advertisements

Introducing JavaScript
Intro to JavaScript. JavaScript History Client (generally browser-side) language invented at Netscape under the name LiveScript around 1995 Netscape wanted.
JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
1 CSC 551: Web Programming Spring 2004 client-side programming with JavaScript  scripts vs. programs  JavaScript vs. JScript vs. VBScript  common tasks.
The Web Warrior Guide to Web Design Technologies
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
Javascript Client-side scripting. Up to now  We've seen a little about how to control  content with HTML  presentation with CSS  Javascript is a language.
Tutorial 10 Programming with JavaScript
XP 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial 10.
Introduction to Web Site Development Steven Emory Department of Computer Science California State University, Los Angeles Lecture 8: JavaScript I.
25-Jun-15 JavaScript Language Fundamentals II. 2 Exception handling, I Exception handling in JavaScript is almost the same as in Java throw expression.
XP Tutorial 9 New Perspectives on JavaScript, Comprehensive1 Working with Cookies Managing Data in a Web Site Using JavaScript Cookies.
CS 299 – Web Programming and Design Overview of JavaScript and DOM Instructor: Dr. Fang (Daisy) Tang.
XP Tutorial 1 New Perspectives on JavaScript, Comprehensive1 Introducing JavaScript Hiding Addresses from Spammers.
2012 •••••••••••••••••••••••••••••••••• Summer WorkShop Mostafa Badr
Review and Practice for Final exam. Final exam Date: December 20, 3:15 – 5:15pm Format: Two parts: First part: multiple-choice questions (15 questions.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
Programming with JavaScript (Chapter 10). XP Various things Midterm grades: Friday Winter Career Fair – Thursday, April 28, 2011 (11 am to 3 pm). – MAC.
JavaScript, Fourth Edition
WEEK 3 AND 4 USING CLIENT-SIDE SCRIPTS TO ENHANCE WEB APPLICATIONS.
Copyright © 2002 ProsoftTraining. All rights reserved. JavaScript Fundamentals.
Week 9 PHP Cookies and Session Introduction to JavaScript.
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
Javascript. Outline Introduction Fundamental of JavaScript Javascript events management DOM and Dynamic HTML (DHTML)
SE-2840 Dr. Mark L. Hornick 1 Modifying webpage behavior using client-side scripting Javascript.
Chapter 8 Cookies And Security JavaScript, Third Edition.
Introduction to JavaScript Gordon Tian
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
JavaScript For...In Statement The for...in statement loops through the elements of an array or through the properties of an object. Syntax for (variable.
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.
School of Computing and Information Systems CS 371 Web Application Programming PHP – Forms, Cookies, Sessions and Database.
Using Client-Side Scripts to Enhance Web Applications 1.
Regular Expression (continue) and Cookies. Quick Review What letter values would be included for the following variable, which will be used for validation.
Lecture 9 The Basics of JavaScript Boriana Koleva Room: C54
 2008 Pearson Education, Inc. All rights reserved JavaScript: Objects.
Keeping it Neat: Functions and JavaScript Source Files Chapter 7.
4.4 JavaScript (JS) Deitel Ch. 7, 8, 9, JavaScript & Java: Similarities JS (JavaScript) is case-sensitive Operators –arithmetic: unary +, unary.
XP Tutorial 10New Perspectives on HTML and XHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial.
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.
JavaScript Scripting language What is Scripting ? A scripting language, script language, or extension language is a programming language.
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming basics.
School of Computing and Information Systems CS 371 Web Application Programming AJAX.
Web111a_chapt08.ppt HTML: Section 8 JavaScript CGI Programs (Server Side programs) Common Gateway Interface Run on server Communicate with user across.
1 JavaScript in Context. Server-Side Programming.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
Rich Internet Applications 2. Core JavaScript. The importance of JavaScript Many choices open to the developer for server-side Can choose server technology.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
1 CSC160 Chapter 1: Introduction to JavaScript Chapter 2: Placing JavaScript in an HTML File.
Introduction to Javascript. What is javascript?  The most popular web scripting language in the world  Used to produce rich thin client web applications.
JavaScript and Ajax Week 10 Web site:
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.
Javascript Prof. Wenwen Li School of Geographical Sciences and Urban Planning 5644 Coor Hall
JAVASCRIPT INTERVIEW QUESTIONS & ANSWERS.
JavaScript an introduction.
Web Systems Development (CSC-215)
PHP.
Tutorial 10 Programming with JavaScript
JavaScript CS 4640 Programming Languages for Web Applications
PHP an introduction.
JavaScript CS 4640 Programming Languages for Web Applications
Presentation transcript:

School of Computing and Information Systems CS 371 Web Application Programming Client-side

School of Computing and Information Systems CS 371 Web Application Programming Web-based Applications Internet clie nt server

School of Computing and Information Systems CS 371 Web Application Programming Desktop vs Web-based traditional desktop applications single user, one location data is stored locally can maintain state as fast as the machine web-based applications data is stored in the cloud stateless data sent over public network as fast as the network/client/server

School of Computing and Information Systems CS 371 Web Application Programming REpresentational State Transfer (REST) software architecture clients and servers client sends request when ready for new state server returns new state with links for new requests constraints client-server stateless cacheable layered system code on demand uniform interface HTTP verbs: GET, POST, PUT, etc.

School of Computing and Information Systems CS 371 Web Application Programming JavaScript Origins Syntax and functions Arrays Objects Special features Accessing the DOM

School of Computing and Information Systems CS 371 Web Application Programming JavaScript Origins 1995: Netscape creates LiveScript (quickly changed to JavaScript) Microsoft introduces VBScript and then Jscript 1996: Netscape proposes ECMAScript specification as a standard 1997: ECMA-262 JavaScript is cross-browser compatible most incompatibility issues arise in differences in the DOM and CSS

School of Computing and Information Systems CS 371 Web Application Programming JavaScript - Implementation scripts can be placed internally using tags externally using typically put functions in the head section and scripts as needed in the body

School of Computing and Information Systems CS 371 Web Application Programming JavaScript basic syntax similar to c/c++, java semicolons at end of lines are optional use to prevent older browsers from displaying javaScript code comments - use both // and /*…*/ JavaScript operates in a sandbox, i.e. browser puts a protective wall around code

School of Computing and Information Systems CS 371 Web Application Programming Operators and control structures operators are similar to C and Java except == and != work with strings if, else, switch are just like Java and C loops - like java including the foreach: for(var in collection) objects uses dot operator for properties and methods Strings have many Java methods Date: var myDate = new Date() (date & time) Math object - like java

School of Computing and Information Systems CS 371 Web Application Programming JavaScript data types and variables JavaScript is not strongly typed data types: strings (use either “ or ‘) boolean (false if undefined, null, 0, NaN, null string) numeric (floating point or integer - limit numbers to  2e31) scope using var inside functions is local global vars declared with var outside function and used inside functions without var

School of Computing and Information Systems CS 371 Web Application Programming Built-in objects several built-in objects with helpful information JavaScript: Array, Boolean, Date, Math, Number, String, RegExp and Global properties and functions Browser objects: Window - represents open window navigator - information about the browser screen - information about the visitor’ screen history - URLs visited by user location - information about current URL

School of Computing and Information Systems CS 371 Web Application Programming Date getDate()Returns day of the month (from 1-31) getDay()Returns the day of the week (from 0-6) getFullYear()Returns the year (four digits) getHours()Returns the hour (from 0-23) getMilliseconds()Returns the milliseconds (from 0-999) getMinutes()Returns the minutes (from 0-59) getMonth()Returns the month (from 0-11) getSeconds()Returns the seconds (from 0-59) Many, many more…

School of Computing and Information Systems CS 371 Web Application Programming Number MAX_VALUEReturns the largest number possible in JavaScript MIN_VALUEReturns the smallest number possible in JavaScript toExponential(x)Converts a number into an exponential notation toFixed(x)Formats a number with x numbers of digits after the decimal point toPrecision(x)Formats a number to x length toString()Converts a Number object to a string valueOf()Returns the primitive value of a Number object

School of Computing and Information Systems CS 371 Web Application Programming String charAt()Returns the character at the specified index concat()Joins two or more strings, and returns a copy of the joined strings fromCharCode()Converts Unicode values to characters indexOf()Returns the position of the first found occurrence of a specified value in a string lastIndexOf()Returns the position of the last found occurrence of a specified value in a string match()Searches for a match between a regular expression and a string, and returns the matches replace()Searches for a match between a substring (or reg exp) and a string, and replaces the matched substring with a new substring search()Searches for a match between a regular expression and a string, and returns the position of the match slice()Extracts a part of a string and returns a new string split()Splits a string into an array of substrings substr()Extracts the characters from a string, beginning at a specified start position, and through the specified number of character substring()Extracts the characters from a string, between two specified indices toLowerCase()Converts a string to lowercase letters toUpperCase()Converts a string to uppercase letters valueOf()Returns the primitive value of a String object

School of Computing and Information Systems CS 371 Web Application Programming Arrays var myArray = new Array(); or var myArray = []; var myArray = new Array(‘one’,’two’); var myArray = [‘one’,’two’]; var scores = new Array(); scores[0]=[94,84,79]; scores[1]=[87,64,90]; course[‘371’]=‘scripps’; //associative?

School of Computing and Information Systems CS 371 Web Application Programming Array concat()Joins two or more arrays, and returns a copy join()Joins all elements of an array into a string pop()Removes the last element of an array, and returns it push()Adds new elements to the end of an array reverse()Reverses the order of the elements in an array shift()Removes the first element of an array, and returns it slice()Selects a part of an array, and returns the new array sort()Sorts the elements of an array splice()Adds/Removes elements from an array toString()Converts an array to a string, and returns the result unshift()Adds new elements to the beginning of an array, and returns the new length valueOf()Returns the primitive value of an array

School of Computing and Information Systems CS 371 Web Application Programming User defined functions function(a,b) { return a*b; } parameters do not need types no return type anonymous functions: var f = new Function(“x”,”y”,”return x+y”); f(6,7); f(“hello”,”world”);

School of Computing and Information Systems CS 371 Web Application Programming User Defined Objects using new Object: var myObj=new Object(); myObject.height=12; using object function: function userObj(parm){…} var obj=new userObj(‘oh hey’); using literal notation: var myObj={name:”miltie”,age:33…}

School of Computing and Information Systems CS 371 Web Application Programming Exceptions runtime errors try, catch and finally are like java except there is only one catch and object is not typed use confirm popup to reroute user to other page: window.location="./anotherPage.htm"; throw - allows programmer to throw except syntax errors onerror=handleErr function handleErr(msg,url,line)

School of Computing and Information Systems CS 371 Web Application Programming Popups Used for debugging and user interaction alert(“hey “+x); //displays info if(confirm(“is this ok?”)==true) var age = prompt(“how old are you?”);

School of Computing and Information Systems CS 371 Web Application Programming Security browsers restrict what JavaScript can do to prevent hacker attacks on clients same-origin policy - scripts cannot communicate across domains

School of Computing and Information Systems CS 371 Web Application Programming Setting cookies document.cookie= “var=val;expire=expireDays;path=aPath” example: var p=“myPassword”; var exp=new Date()+30; document.cookie=“pass=“+p+”;expires=“+ exp.toUTCString(); set expires to yesterday to delete

School of Computing and Information Systems CS 371 Web Application Programming Getting cookies cookies are stored as one big string var i=cookie.indexOf(“pass=“); if(i>=0){ var str=cookie.substring(i,cookie.length); var last=str.indexOf(“;”); if(last<0) last=str.length; str=str.substring(0,last).split(“=“); cookie is in str[1]