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

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

XML Applications. Prof. Andrea Omicini DEIS, Ingegneria Due Alma Mater Studiorum, Università di Bologna a Cesena

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. UNIVERSITY OF MASSACHUSETTS AMHERST CMPSCI 120 Fall 2010

Building Desktop RIAs with PHP, HTML & Javascript in AIR. Ed Finkler, ZendCon08, September 17, 2008 funkatron.com /

Session 16. JavaScript Part 1. Reading

Client-Side Web Technologies. JavaScript Part I

Client vs Server Scripting

Session 6. JavaScript Part 1. Reading

Vebra Search Integration Guide

Introduction to HTML5

JavaScript Lecture 1

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

Unit Notes. ICAWEB411A Produce basic client-side script for dynamic web pages Topic 1 Introduction to JavaScript

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

CSC Web Programming. Introduction to JavaScript

Implementing a chat button on TECHNICAL PAPER

Lecture 3: The Basics of JavaScript. Background. Needs for Programming Capability. Origin of JavaScript. Using Client-side JavaScript

JavaScript: The Basics

JavaScript CS 4640 Programming Languages for Web Applications

JavaScript: Introduction, Types

CS312: Programming Languages. Lecture 21: JavaScript

CGS 3066: Spring 2015 JavaScript Reference

JavaScript Specialist v2.0 Exam 1D0-735

Produced by. App Development & Modeling. BSc in Applied Computing. Eamonn de Leastar

The first sample. What is JavaScript?

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

A designers guide to creating & editing templates in EzPz

Web Systems & Technologies: An Introduction

JavaScript Introduction

Web Systems & Technologies: An Introduction

blink.html 1/1 lectures/6/src/ form.html 1/1 lectures/6/src/

E ECMAScript, 21 elements collection, HTML, 30 31, 31. Index 161

5. JavaScript Basics

function < name > ( < parameter list > ) { < statements >

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

HTML Overview. With an emphasis on XHTML

Basics of JavaScript. Last Week. Needs for Programming Capability. Browser as Development Platform. Using Client-side JavaScript. Origin of JavaScript

Background. Javascript is not related to Java in anyway other than trying to get some free publicity

JavaScript: Getting Started

JavaScript CS 4640 Programming Languages for Web Applications

Lecture 8 (7.5?): Javascript

How the Internet Works

JAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1)

Design Project. i385f Special Topics in Information Architecture Instructor: Don Turnbull. Elias Tzoc

Building Your Blog Audience. Elise Bauer & Vanessa Fox BlogHer Conference Chicago July 27, 2007

Javascript. Daniel Zappala. CS 360 Internet Programming Brigham Young University

This course is designed for web developers that want to learn HTML5, CSS3, JavaScript and jquery.

Working with JavaScript

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

introduction to XHTML

New Media Production HTML5

JavaScript: The Definitive Guide

COMS W3101: SCRIPTING LANGUAGES: JAVASCRIPT (FALL 2017)

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

The Architecture of the World Wide Web

Web Development & Design Foundations with XHTML. Chapter 2 Key Concepts

Chapter 14 JavaScript and DHTML

JavaScript - The Definitive Guide, 5th Edition

Computer Science E-75 Building Dynamic Websites

COMP519 Web Programming Lecture 11: JavaScript (Part 2) Handouts

The Architecture of the World Wide Web

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

JAVASCRIPT. Ajax Technology in Web Programming. Sergio Luján Mora. DLSI - Universidad de Alicante 1. Basic syntax and features

UNIT -II. Language-History and Versions Introduction JavaScript in Perspective-

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

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

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

Session 7. JavaScript Part 2. W3C DOM Reading and Reference

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

Processes in Distributed Systems

JavaScript. What s wrong with JavaScript?

Chapter 4 Basics of JavaScript

UNIT-4 JAVASCRIPT. Prequisite HTML/XHTML. Origins

JavaScript: Sort of a Big Deal,

<form>. input elements. </form>

HyperText Markup Language (HTML)

Client-side Processing

JavaScript (5A) JavaScript

JavaScript: Introductionto Scripting

ajax1.html 1/2 lectures/7/src/ ajax1.html 2/2 lectures/7/src/

JavaScript Developer's Dictionary

Processes in Distributed Systems

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

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

Fault Tolerance in Distributed Systems: An Introduction

extensible Markup Language (XML) Basic Concepts

COMP284 Scripting Languages Lecture 14: JavaScript (Part 1) Handouts

Princess Nourah bint Abdulrahman University. Computer Sciences Department

LA TROBE UNIVERSITY SEMESTER ONE EXAMINATION PERIOD CAMPUS AW BE BU MI SH ALLOWABLE MATERIALS

I Can t Believe It s Not

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

Tutorial on text transformation with pure::variants

INF5750. Introduction to JavaScript and Node.js

Project 3 CIS 408 Internet Computing

Chapter 3 Data Types and Variables

Functions. INFO/CSE 100, Spring 2006 Fluency in Information Technology.

Tutorial 10: Programming with JavaScript

Manju Muralidharan Priya. CS4PM Web Aesthetics and Development WEEK 12

Ruby: Introduction, Basics

Transcription:

Introduction to Prof. Ing. Andrea Omicini II Facoltà di Ingegneria, Cesena Alma Mater Studiorum, Università di Bologna andrea.omicini@unibo.it Documents and computation HTML Language for the description of documents Information-oriented Document mobility Distributed information How to distribute computation using the Web? Associating mobile code to HTML pages Applet Java 2 vs. Java Applet Specialisation on the client as browser model Dynamics Lightness Regular Expressions agile management Perl-like Weakly typed easy prototyping Inheritance and objects prototype vs. class Myths is similar to Java A little is simple It is easily usable without training runs on every browser Yes, of course, thankyouverymuch but it can have specific quirks on specific browsers Versions, IE vs Mozilla (Netscape) vs Opera vs ECMA http://www.ecma-international.org/ 3 4 Standard ECMA 262 ISO 16262 ECMAScript, Jscript http://www.ecma-international.org/publications/standards/ecma-262.htm http://www.ecma-international.org/publications/files/ecma-st/ecma-262.pdf ECMA 357 E4X ECMAScript for XML http://www.ecma-international.org/publications/standards/ecma-357.htm http://www.ecma-international.org/publications/files/ecma-st/ecma-357.pdf Object-oriented / Functional language Model Syntactic details Client side Browser integration Server side We are not interested Embedded I have not heard about that in a long time 5 6

Example XHTML Example <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title></title> <link href ="style.css" rel="stylesheet" type="text/css" media="screen" /> <script type="text/javascript" src="command.js"></script> </head> <body class="papers"> <form action="" method="get"> <input type="button" value="bibtex" class="bibbtn" onclick="showbib('volume');"> absurl = "abs/"; biburl = "bib/"; pdfurl = "pdf/"; function showabs(key) { abstractwin=window.open(absurl+key+".html","abstractwindow", "resizable=yes,dependent=yes,height=150,width=600,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no"); abstractwin.focus(); function showbib(key) { bibtexwin=window.open(biburl+key+".html","bibtexwindow", "resizable=yes,dependent=yes,height=300,width=600,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no"); bibtexwin.focus(); function showpdf(key) { top.location.href=pdfurl+key+".pdf"; 7 8 What does do? Document content and presentation control The document object DOM Browser control The window object Form management The Form, Button, objects User interaction Events management Interaction state management Cookies Structure of the language Case sensitive It is a problem using HTML Separators Spaces, line breaks, tabs, Semicolon Optional, but please use it Comments Similar to C, C++ e Java Use // for single line and /* */ for multiline Keywords 9 10 Data types Numbers Primitive types Number, string and boolean Objects General e special window, document, Data, RegExp, Array Functions E4X adds XML-like data types Integer and real numbers as IEEE 8 byte Only double-precision numbers The Math object Library of mathematical functions Special values Infinity NaN 11 12

Strings Boolean No char type Quotes and double quotes they are equal pay attention with (X)HTML Concatenation and many other classic operators Wrapper String Virtual library, à la Java (static functions) false and true As strings Automatically converted in 0 and 1 Numbers Whenever needed 13 14 Primitive types and references Variables and scope Assignment Between non-primitive types References are shared Example var a = [1,2,3]; var b = a; a[0] = 99; alert(b); what does that do? Try it! (IE, Mozilla, Opera, Safari/Konqueror) javascript: var a = [1,2,3]; var b = a; a[0] = 99; alert(b); what is the output? Keyword var Used or not Scopes Global Global object Local Execution context No blocks Web documents and windows are new context in addition to classic scopes 15 16 Expressions and operators Control instructions We won t present them Similar to C, C++, Java, more or less Please help yourself There s all sort of them Note typeof a kind of reflexive operator Selection if, if/else, else if switch Iteration while, do/while, for, for/in Function function, return 17 18

Functions First class objects Parameters Lambda expression, closures Examples function square(x) {return x*x; var square = new Function( x, return x*x; ; var square = function(x) {return x*x;; Function objects and properties The call object arguments, caller length and arity apply and call Objects Collections of properties with names The new operator var paper = new Object(); Definition of / access to properties paper.title = -- Ohboy!!! ; Enumeration for/in Metods Properties like any other Prototypes Not (only) classes and inheritance In the 3rd standard, class and prototype properties 19 20 Array Regular Expressions As objects var arr = new Array(1,2,3,4,5); Classic access var four = arr[3]; var arr = [[2,3],[true,false],[ boh, mah ]]; Fragmented and dynamic you can do everything you want Wrapper Array Excellent to manage text User input The RegExp object A lot of relevant details... Ok, let s move on! 21 22 Browser integration The SCRIPT tag The window object Window as a global execution context var foo and window.foo are the same Client-side object hierarchy The window object contains document, location, frames[], forms[], Event model Event managers associated to (X)HTML tags <html> <head> <script type="text/javascript" language=""> <!-- hide to very old browsers javascript code --> </script> </head> 23 24

Windows management You can control almost everything but you need to study a little so it is better to start from existing examples A window objects hierarchy screen, navigator, document, function showbib(key) { bibtexwin=window.open(biburl+key+".html","bibtexwindow", "resizable=yes,dependent=yes,height=300,width=600,location=no,menubar=no, scrollbars=yes,status=no,toolbar=no"); bibtexwin.focus(); function showpdf(key) { top.location.href=pdfurl+key+".pdf"; DOM Standardize the Document Object Model It has been done in theory, but in practice there are still some problems especially using frames To dynamically generate objects document.write(), writeln(), open(), close() 25 26 Events Event managers onchange, onclick, onmousedown, onsubmit, Problem to define a set of common events between IE and the other browsers it has been tried Managers as HTML attributes <form action="" method="get"> <input type="button" value="bibtex" class="bibbtn" onclick="showbib('volume');"> HTML and Forms Every (X)HTML element can have an identifier The id attribute (once called name) The Form object Modules as elements of document.forms[] Input elements as elements of document.forms [].elements[] Associative access using the name/id name The onsubmit() and reset() methods If onsubmit() returns false, data are not sent A crystal-clear example of distributed computation 27 28 Security Implicit No access to the local file system No direct network functions Explicit Restricted or privilege based functionality From the same origin rule Signed script in a few hours? Tutorial on the Internet Course website or http://www.google.it, search: Tutorial Example http://www.pageresource.com/jscript/ tutorial page http://academ.hvcc.edu/~kantopet/old/javascript/ Books : The Definitive Guide (David Flanagan, O Reilly/Apogeo) or anything you like 29 30