Client vs Server Scripting

Similar documents
JAVASCRIPT. JavaScript is the programming language of HTML and the Web. JavaScript Java. JavaScript is interpreted by the browser.

JavaScript CS 4640 Programming Languages for Web Applications

JavaScript CS 4640 Programming Languages for Web Applications

Web Programming and Design. MPT Junior Cycle Tutor: Tamara Demonstrators: Aaron, Marion, Hugh

JavaScript: the Big Picture

Place User-Defined Functions in the HEAD Section

JavaScript Introduction

Lecture 14. Introduction to JavaScript. Mr. Mubashir Ali Lecturer (Dept. of Computer Science)

By the end of this section of the practical, the students should be able to:

LECTURE-3. Exceptions JS Events. CS3101: Programming Languages: Javascript Ramana Isukapalli

CGS 3066: Spring 2015 JavaScript Reference

Javascript. UNIVERSITY OF MASSACHUSETTS AMHERST CMPSCI 120 Fall 2010

Introduction to JavaScript p. 1 JavaScript Myths p. 2 Versions of JavaScript p. 2 Client-Side JavaScript p. 3 JavaScript in Other Contexts p.

JavaScript and XHTML. Prof. D. Krupesha, PESIT, Bangalore

8/19/2018. Web Development & Design Foundations with HTML5. Learning Objectives (1 of 2) Learning Objectives (2 of 2) What is JavaScript?

Web Development & Design Foundations with HTML5

Web Development & Design Foundations with HTML5, 8 th Edition Instructor Materials Chapter 14 Test Bank

Documents and computation. Introduction to JavaScript. JavaScript vs. Java Applet. Myths. JavaScript. Standard

Working with JavaScript

Welcome to CS50 section! This is Week 10 :(

Session 6. JavaScript Part 1. Reading

INLEDANDE WEBBPROGRAMMERING MED JAVASCRIPT INTRODUCTION TO WEB PROGRAMING USING JAVASCRIPT

CSC Web Programming. Introduction to JavaScript

JavaScript. What s wrong with JavaScript?

Introduction to DHTML

CSS The web browser uses its own resources, and eases the burden on the server. It has fewer features than server side scripting.

JavaScript By: A. Mousavi & P. Broomhead SERG, School of Engineering Design, Brunel University, UK

Elementary Computing CSC 100. M. Cheng, Computer Science

Session 16. JavaScript Part 1. Reading

710 Index Attributes, 127 action attribute, 263 assigning, bottom attribute, domain name attribute, 481 expiration date attribute, 480 8

CS312: Programming Languages. Lecture 21: JavaScript

CISH-6510 Web Application Design and Development. Overview of JavaScript. Overview

Why Discuss JavaScript? CS312: Programming Languages. Lecture 21: JavaScript. JavaScript Target. What s a Scripting Language?

New Perspectives on Creating Web Pages with HTML. Tutorial Objectives

HTML User Interface Controls. Interactive HTML user interfaces. Document Object Model (DOM)

ENRICHING PRIMO RECORDS WITH INFORMATION FROM WORDPRESS. Karsten Kryger Hansen Aalborg University Library

extc Web Developer Rapid Web Application Development and Ajax Framework Using Ajax

INTRODUCTION TO JAVASCRIPT

COMP519 Web Programming Lecture 16: JavaScript (Part 7) Handouts

JavaScript: The Basics

Outline. Introduction to JavaScript Resources What is JavaScript? JavaScript in web pages

Fundamentals of Website Development

Princess Nourah bint Abdulrahman University. Computer Sciences Department

Events: another simple example

Introduction to JavaScript

jquery and AJAX

LECTURE-2. Functions review HTML Forms. Arrays Exceptions Events. CS3101: Scripting Languages: Javascript Ramana Isukapalli

Frontend II: Javascript and DOM Programming. Wednesday, January 7, 15

The first sample. What is JavaScript?

CS Final Exam Review Suggestions - Spring 2018

IN Development in Platform Ecosystems Lecture 2: HTML, CSS, JavaScript

Towards Improving the Reliability of JavaScript-based Web 2.0 Applications

Outline. Lecture 4: Document Object Model (DOM) What is DOM Traversal and Modification Events and Event Handling

JavaScript. History. Adding JavaScript to a page. CS144: Web Applications

CS1520 Recitation Week 2

JavaScript Handling Events Page 1

Controlled Assessment Task. Question 1 - Describe how this HTML code produces the form displayed in the browser.

3 The Building Blocks: Data Types, Literals, and Variables

By the end of this section of the practical, the students should be able to:

JavaScript is described in detail in many books on the subject, and there is excellent tutorial material at

JavaScript s role on the Web

A.A. 2008/09. Why introduce JavaScript. G. Cecchetti Internet Software Technologies

5. JavaScript Basics

Web Programming HTML CSS JavaScript Step by step Exercises Hans-Petter Halvorsen

Interactor Tree. Edith Law & Mike Terry

INF5750. Introduction to JavaScript and Node.js

Such JavaScript Very Wow

Jinx Malware 2.0 We know it s big, we measured it! Itzik Kotler Yoni Rom

Princeton University COS 333: Advanced Programming Techniques A Subset of JavaScript

CISC 1600 Lecture 2.4 Introduction to JavaScript

Elementary Computing CSC 100. M. Cheng, Computer Science

JavaScript. History. Adding JavaScript to a page. CS144: Web Applications

Tizen Web UI Technologies (Tizen Ver. 2.3)

A Balanced Introduction to Computer Science, 3/E

Ajax HTML5 Cookies. Sessions 1A and 1B

CITS1231 Web Technologies. JavaScript

Client-side Techniques. Client-side Techniques HTML/XHTML. Static web pages, Interactive web page: without depending on interaction with a server

COMS 469: Interactive Media II

this is a cat CS50 Quiz 1 Review

JAVASCRIPT HTML DOM. The HTML DOM Tree of Objects. JavaScript HTML DOM 1/14

Ruby: Introduction, Basics

JavaScript code is inserted between tags, just like normal HTML tags:

BEFORE CLASS. If you haven t already installed the Firebug extension for Firefox, download it now from

JS Tutorial 3: InnerHTML Note: this part is in last week s tutorial as well, but will be included in this week s lab

Notes on JavaScript (aka ECMAScript) and the DOM

Midterm Exam. 5. What is the character - (minus) used for in JavaScript? Give as many answers as you can.

Ruby: Introduction, Basics

IT2353 WEB TECHNOLOGY Question Bank UNIT I 1. What is the difference between node and host? 2. What is the purpose of routers? 3. Define protocol. 4.

Ruby: Introduction, Basics

Web Designing Course

The course is supplemented by numerous hands-on labs that help attendees reinforce their theoretical knowledge of the learned material.

Client-Side Web Technologies. JavaScript Part I

JavaScript Specialist v2.0 Exam 1D0-735

Princeton University COS 333: Advanced Programming Techniques A Subset of JavaScript

Web Programming/Scripting: JavaScript

isnan function returns true if the argument is not a number otherwise it is false.

CHAPTER 6 JAVASCRIPT PART 1

CSC 337. JavaScript Object Notation (JSON) Rick Mercer

1$ 5 ! $ 6 4 * Source: 0 "!*! 0! * 8 97 ?!$ 5 0 *! 4! $ 0 : * ' () 7;7 7<7

Unobtrusive JavaScript. Lecture Outline. CSE 190 M (Web Programming), Spring 2008 University of Washington

Transcription:

Client vs Server Scripting PHP is a server side scripting method. Why might server side scripting not be a good idea? What is a solution? We could try having the user download scripts that run on their local machine. This is called client side scripting.

Client- Side Scrip.ng download a script/program to the browser, and have it execute within the browser environment: o JavaScript / ECMAScript / JScript o VBScript o TCL we will examine JavaScript as a proxy for this group of client-side languages; much of what we study is immediately transferable to other languages in the group JavaScript is the dominant client-side programming language the basis for much of what we now refer to as Rich Internet Applications (RIA) or Web 2.0

Client- Side Scrip.ng Advantages : o Immediate responsiveness no need for network data exchange with server and page reload by browser e.g. jquery list filtering client-side data validation local code often 10-100 times faster than server interaction o Potential for offline Web apps (supported in HTML5) o Off loads processing tasks to client that is usually less loaded than server

Client- Side Scrip.ng Disadvantages: o scripts themselves must be downloaded from server, increasing size and time for page loads o scripts are readable, can t protect source code (IP), though can obfuscate them o security risk posed by downloaded code; e.g. much of today s malware utilizes client-side scripting to enter your computer

History and Java Relationship JS had to look like Java only less so, be Java s dumb kid brother or boy-hostage sidekick. Plus, I had to be done in ten days or something worse than JS would have happened." -- Brandon Eich, Netscape Communications A lot of syntactic overlap with Java, e.g. comments, if-stmts, forloops, while-stmts are the same as in Java. Some things are very different, e.g. data typing rules, class/object handling, handling of Boolean values, variable scoping, treatment of functions

Using JavaScript In an HTML document, we place JavaScript inside <script> </script> tags. These tags can appear in the <head> </head> or the <body> </body> Can include from a file using: <script language=javascript src= file.js > </script> 6

Key JS Concepts The document object allows us to refer to and change the webpage. document.write( Hi there. ); document.bgcolor( black ); document.fgcolor( red ); Set html content using innerhtml: document.getelementbyid( my_id ).innerhtml = new stuff ; Message Boxes: window.alert( Welcome ); window.confirm( Do you want to quit? ); window.prompt( Please enter your age: );

Event Handlers We can make the page dynamic with events: <some-html-element some-event= JavaScript'> Event handlers Can be a buaon, image, div. onclick onchange onload onmouseover, onmouseout onkeydown onunload Can be a function().

Using Javascript <!DOCTYPE html> <html> <head> <script> function myfunction() { document.getelementbyid("demo").innerhtml = "Paragraph changed."; } </script> </head> <body> Event handler <p id="demo">a Paragraph.</p> <button type="button" onclick="myfunction()">try it</button> </body></html>

JavaScript Typing Dynamically typed m different than Java or C more like Python, and takes some ideas from functional languages like Scheme m a variable can hold any type of value: q number (8-byte IEEE fp) q string q boolean q function (first-class data type) q Object (DOM or JS) q array (whose elements can be of mixed types) m and can hold values of different types at different times during execution!

JavaScript variables Variable declaration var i = 12, msg = hello ; No block-level scope; what will this function display when called? Example block.html function test() { if ( 1 == 1 ) { var j = 12; } alert(j); // displays what? }

JavaScript Variables Caution If you omit a variable declaration (keyword var): The variable is automatically declared at global scope. May seem like a small point, but beware! can lead to subtle hard-to track-down bugs

Literals Usual number, string, boolean literals Function literals (anonymous, lambda functions) var square = function(x) { return x*x; } Object literals var point = { x:2, y:4 }; Array literals (mixed type) var a = [1, foo,true]; Regular expression literals var a = /[1-9][0-9]*/; Ø creates object of type RegExp CSCB20 Databases and Web Apps JavaScript and jquery 13

JavaScript Comments // single-line comment /* * multi-line comment * multi-line comment */

JavaScript Control Flow if statement: if (test) { statements; } else if (test) { statements; } else { statements; } identical structure to Java's if statement... but JavaScript allows almost any value as a test!

JavaScript Control Flow for loop: for (init; test; update) { statements; } for (var i=0; i<10; i++) { print(i + "\n"); } same as Java while loop: while (test) { statements; } do { statements; } while (test); break and continue keywords same as Java

Boolean values: JavaScript Booleans q false-ish : 0, 0.0, NaN, "", null, undefined q true-ish : all other values Unusual treatment of Boolean values can lead to hard-to-find bugs.

JavaScript the Language Cau.ons testing for wrong false-ish value can have bad results: function login(user) { // passes with 0, "", undefined, false,... if (user.name == null) {... } == produces odd results for false-ish values: "" == false // true 0 == false // true "0" == false // true "" == '0' // false "" == 0 // true null == undefined // true " \t \n " == 0 // true

Document Object Model (DOM) q In the pre- standardized world, browsers had different API s different implementa.ons for different browsers = bad news for developers. q The Document Object Model (DOM) is a W3C standard plasorm- (browser) and language- neutral interface (API) q Allows programs and scripts to dynamically access and update the content, structure and style (virtually all proper.es) of documents (both HTML and XML, although the DOM is targeted more at XML). q Standard is not uniformly implemented by browsers, so some browser- specific code s.ll needed (jquery hides these differences)

DOM: Referencing Objects <body> <form id="myform" name="myform"> <input id="b1" type="button" name="turniton"/> </form> </body> by ID (the preferred approach, why?) document.getelementbyid("b1") by element type document.getelementsbytagname( a") by location within DOM tree (why is this a bad idea?) document.forms[0].elements[0] by element name (deprecated, but still widely used) document.myform.turniton