Key features. Nothing to do with java It is the Client-side scripting language Designed to add interactivity to HTML pages

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

JAVASCRIPT BASICS. Handling Events In JavaScript. In programing, event-driven programming could be a programming

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

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

CSC Javascript

Fundamentals of Website Development

Pearson Education Limited Edinburgh Gate Harlow Essex CM20 2JE England and Associated Companies throughout the world

New Perspectives on Creating Web Pages with HTML. Tutorial Objectives

Introduction to DHTML

Events: another simple example

Want to add cool effects like rollovers and pop-up windows?

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

JavaScript Handling Events Page 1

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

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

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

DOM Primer Part 2. Contents

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

The first sample. What is JavaScript?

Beijing , China. Keywords: Web system, XSS vulnerability, Filtering mechanisms, Vulnerability scanning.

UNIT - III. Every element in a document tree refers to a Node object. Some nodes of the tree are

JSF - H:INPUTSECRET. Class name of a validator that s created and attached to a component

New Media Production Lecture 7 Javascript

Javascript. A key was pressed OR released. A key was released. A mouse button was pressed.

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

Canvas & Brush Reference. Source: stock.xchng, Maarten Uilenbroek

Installation and Configuration Manual

GRITS AJAX & GWT. Trey Roby. GRITS 5/14/09 Roby - 1

INTRODUCTION TO WEB DEVELOPMENT AND HTML. Lecture 15: JavaScript loops, Objects, Events - Spring 2011

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

Photo from DOM

Session 16. JavaScript Part 1. Reading

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

Client-Side Web Programming. Copyright 2017 by Robert M. Dondero, Ph.D. Princeton University

link document.getelementbyid("coffee").style.borderwidth = "0px" document.getelementbyid("tea").style.borderwidth = "10px"

Session 6. JavaScript Part 1. Reading

IS 242 Web Application Development I

Contents. Demos folder: Demos\14-Ajax. 1. Overview of Ajax. 2. Using Ajax directly. 3. jquery and Ajax. 4. Consuming RESTful services

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

JSF - H:SELECTONEMENU

Introduction to JavaScript, Part 2

CITS3403 Agile Web Development Semester 1, 2018

Place User-Defined Functions in the HEAD Section

Q1. What is JavaScript?

JSF - H:SELECTONERADIO

Name Related Elements Type Default Depr. DTD Comment

An Introduction to AJAX. By : I. Moamin Abughazaleh

Full file at Tutorial 2: Working with Operators and Expressions

Notes General. IS 651: Distributed Systems 1

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

AJAX Securely by Matt Payne, CISSP

User Interaction: jquery

INDEX SYMBOLS See also

Part of this connection identifies how the response can / should be provided to the client code via the use of a callback routine.

Note: Java and JavaScript are two completely different languages in both concept and design!

Dynamic Web Pages - Integrating JavaScript into a SAS Web Application Caroline Bahler, ASG, Inc.

AJAX: Rich Internet Applications

JSF - H:PANELGRID. JSF Tag. Rendered Output. Tag Attributes. The h:panel tag renders an HTML "table" element. Attribute & Description.

Ajax HTML5 Cookies. Sessions 1A and 1B

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

Chapter 14 - Dynamic HTML: Event Model

TEXTAREA NN 2 IE 3 DOM 1

Dynamic HTML becomes HTML5. HTML Forms and Server Processing. Form Submission to Web Server. DHTML - Mouse Events. CMST385: Slide Set 8: Forms

Web Engineering (Lecture 06) JavaScript part 2

Skyway Builder Web Control Guide

Continues the Technical Activities Originated in the WAP Forum

Outline. AJAX for Libraries. Jason A. Clark Head of Digital Access and Web Services Montana State University Libraries

Javascript Lecture 23

Digitizing Sound and Images III Storing Bits

CISC 1600 Lecture 2.4 Introduction to JavaScript

Introduction to JavaScript

Lesson 12: JavaScript and AJAX

This tutorial has been designed for beginners in HTML5 to make them understand the basicto-advanced

Experience the Magic of On-the-fly Modernization. Screen Customization Guide. for Genie Version 3.0

JAVASCRIPT FOR PROGRAMMERS

Client vs Server Scripting

AJAX. Introduction. AJAX: Asynchronous JavaScript and XML

DC71 INTERNET APPLICATIONS JUNE 2013

JavaScript Introduction

Scripting. Web Architecture and Information Management [./] Spring 2009 INFO (CCN 42509) Contents

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

Module 5 JavaScript, AJAX, and jquery. Module 5. Module 5 Contains 2 components

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

JavaScript Programming Chris Seddon

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

A.A. 2008/09. What is Ajax?

AJAX and PHP AJAX. Christian Wenz,

Sections and Articles


3Lesson 3: Functions, Methods and Events in JavaScript Objectives

JavaScript. Asst. Prof. Dr. Kanda Saikaew Dept. of Computer Engineering Khon Kaen University

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

Developing for Ajax. Ajax 101. A Look Under the Hood. Bill W. Scott, Y! Ajax Evangelist.

COURSE OUTLINE MOC 20480: PROGRAMMING IN HTML5 WITH JAVASCRIPT AND CSS3

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

Creating an Online Catalogue Search for CD Collection with AJAX, XML, and PHP Using a Relational Database Server on WAMP/LAMP Server

AJAX Workshop. Karen A. Coombs University of Houston Libraries Jason A. Clark Montana State University Libraries

UNIT 3 SECTION 1 Answer the following questions Q.1: What is an editor? editor editor Q.2: What do you understand by a web browser?

XMLHttpRequest. CS144: Web Applications

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

Transcription:

Javascript

Key features Nothing to do with java It is the Client-side scripting language Designed to add interactivity to HTML pages (DHTML): Event-driven programming model AJAX Great example: Google Maps Embedded directly into HTML pages or imported from separate file Popular libraries: Jquery, Prototype

Key features JavaScript is an Object Oriented Programming (OOP) language Built-in JavaScript objects The document itself is an object (Document Object Model, DOM) inside the window browser An object has properties and methods New objects can be created but No class construct!

Key features Event-driven computation model Code (function) is activated (triggered) when an event occurs The effect of the code is on The document being displayed The window (open a new windows, pop-up, etc) Make a HTTP request

Mobile for applications Increasing interest for web-based mobile applications All popular browser do support JS, e.g. Safari Allows to access device information, e.g., geolocation Android, iphone HTML 5 http://ofps.oreilly.com/titles/9781449383268/index.html

Mash up applications Many Web API are provided as JS library, e.g., Geonames, Google map, nextdb, etc

Attribute The event occurs when... onabort onblur onchange onclick ondblclick onerror onfocus onkeydown onkeypress onkeyup Loading of an image is interrupted An element loses focus The user changes the content of a field Mouse clicks an object Mouse double-clicks an object An error occurs when loading a document or an image An element gets focus A keyboard key is pressed A keyboard key is pressed or held down A keyboard key is released onload onmousedown onmousemove onmouseout onmouseover onmouseup onreset onresize onselect onsubmit onunload A page or an image is finished loading A mouse button is pressed The mouse is moved The mouse is moved off an element The mouse is moved over an element A mouse button is released The reset button is clicked A window or frame is resized Text is selected The submit button is clicked The user exits the page

Object hierarchy

Navigator.Geolocation

Javascript vs PHP HTTP Request CLIENT SERVER HTTP reply <html> <body> <script type="text/javascript"> document.write("hello World!"); </script> </body> </html> rendering

Javascript vs PHP HTTP Request CLIENT SERVER HTTP reply Hello, World php module executes the script <?php print "Hello, World";?> sends back the output

Where to put a script Scripts to be executed when they are called, or when an event is triggered, go in the head section. Scripts to be executed when the page Scripts to be executed when the page loads go in the body section.

OO example <script type="text/javascript"> var txt="hello World!"; document.write(txt.length); document.write(txt.touppercase()); </script> Length is a property of the String object touppercase is a method of the String object 12 HELLO WORLD!

An example <html> <body> Field1: <input type="text" id="field1" value="hello World!"> <br /> Field2: <input type="text" id="field2"> <br /><br /> Click the button below to copy the content of Field1 to Field2. <br /> <button onclick="document.getelementbyid('field2').value= document.getelementbyid('field1').value"> Copy Text </button> </body> </html>

<html> <head> <script type="text/javascript"> function Foo() { document.getelementbyid('field2').value= document.getelementbyid('field1').value;} </script> </head> <body> Field1: <input type="text" id="field1" value="hello World!"> <br /> Field2: <input type="text" id="field2"> <br /><br /> Click the button below to copy the content of Field1 to Field2. <br /> <button onclick= Foo() > Copy Text </button> </body> </html> Function Foo registered to the onclick event Foo its event listener

AJAX Asynchronous JavaScript And XML. a type of programming made popular in 2005 by Google (with Google Suggest). based on JavaScript and HTTP requests JavaScript can communicate directly with the server, using the JavaScript XMLHttpRequest object. With this object, JavaScript can trade data with a web server, without reloading the page For security reasons, requests can only sent to the same domain from which the page is loaded

XMLHttpRequest specification

Architecture AJAX allows to reduce the granularity of data exchanged A single element instead of the entire document

Example Read data from a text input in an input form Call a PHP function for echoing the character What we need Keyboard event listener (JS function) AJAX request that passes the text to the script PHP script that echo the text back to the client

In this form there is no submit button JS function called when key is released <form name="testform"> Input text: < input type="text" onkeyup="dowork();" name="inputtext" id="inputtext" /> Output text: <input type="text" name="outputtext" id="outputtext" /> </form>

function do_it() { document.testform.outputtext.value=request.responsetext; };.. var request = false;.. function dowork(){ var URL = "http://localhost/test.php?char="; request = new XMLHttpRequest(); request.open("get", URL+document.getElementById('inputText').value, true); request.send(null); request.onreadystatechange = do_it; } open method used for preparing the request send sends the request do_it is the event listener for the reply php script <?php echo $_GET['char'];?>

Example TrackMe, a simple application that tracks positions of a mobile device: track.html: js that sends gps position trackme.php: write the coordinate to a file Monitor.php: periodically reads the file and shows the positions.

Example 1 track.html Browser.js monitor.php 2: HTTP GET trackme.php

track.html (1/2) <html> <head> <title> Track Me!</title> </head> <body> <input type="text" id = "text" value="" size=100/> <script type="text/javascript"> function done() { document.getelementbyid('text').value="tracked.."; }

track.html (2/2) navigator.geolocation.getcurrentposition(showposition); function showposition(position) { var lat=position.coords.latitude; var lon=position.coords.longitude; var URL = "http://psd.altervista.org/geo/trackme.php?lat="+lat+"&lon="+lon; request = new XMLHttpRequest(); request.open("get", URL, true); request.send(null); request.onreadystatechange = done; document.getelementbyid('text').value="long: "+lon+" Lat: "+lat; } </script> </body> </html>

TrackMe trackme.php <?php $lat='?'; $lon='?'; if (isset($_get['lat'])) $lat=$_get['lat']; if (isset($_get['lon'])) $lon=$_get['lon']; $entry=date(c).' '.$lat.' '.$lon."\n"; file_put_contents ('position.txt', $entry, FILE_APPEND);?> Monitor.php <head> <meta http-equiv="refresh" content="5" > </head> <?php $str=file_get_contents('position.txt'); echo nl2br($str);?>

Including library <script type="text/javascript" src="http://xxx.yyy.zzz/abc.js"></script>

An example

An example

Example Show a map into the browser, centered at your current location The current location is given by: a simple form (if accessing from a PC) Automatically if a GPS device is available

LAB Get the photo closest to your position from Flickr