Javascript. Interacting with web pages. by Aaron Wheeler Design Prototyper, Yahoo! Inc.

Similar documents
Example. Represent this as XML

Performance Testing for Ajax Applications

AJAX and JSON Lessons Learned. Jim Riecken, Senior Software Engineer, Blackboard Inc.

MASTERTAG DEVELOPER GUIDE

DOM, Jav Ja a v Script a and AJA AJ X A Madalina Croitoru IUT Mont Mon pellier

jquery Tutorial for Beginners: Nothing But the Goods

JavaScript Basics & HTML DOM. Sang Shin Java Technology Architect Sun Microsystems, Inc. sang.shin@sun.com

CRM Developer Form

JavaScript: Client-Side Scripting. Chapter 6

Performance Testing Web 2.0

Chapter 12: Advanced topic Web 2.0

Types of Cloud Computing

Programming in HTML5 with JavaScript and CSS3

WEB DEVELOPMENT COURSE (PHP/ MYSQL)

A Model of the Operation of The Model-View- Controller Pattern in a Rails-Based Web Server

Overview. In the beginning. Issues with Client Side Scripting What is JavaScript? Syntax and the Document Object Model Moving forward with JavaScript

CSC309 Winter 2016 Lecture 3. Larry Zhang

Mobile Web Design with HTML5, CSS3, JavaScript and JQuery Mobile Training BSP-2256 Length: 5 days Price: $ 2,895.00

Advanced Web Development SCOPE OF WEB DEVELOPMENT INDUSTRY

The purpose of jquery is to make it much easier to use JavaScript on your website.

Advantage of Jquery: T his file is downloaded from

Some Issues on Ajax Invocation

Interactive Data Visualization for the Web Scott Murray

Creating and Configuring a Custom Visualization Component

This matches a date in the MM/DD/YYYY format in the years The date must include leading zeros.

XML Processing and Web Services. Chapter 17

Client-Side Web Programming (Part 2) Robert M. Dondero, Ph.D. Princeton University

Best Practices for Rich Media Ads in Asynchronous Ad Environments

Software Development Interactief Centrum voor gerichte Training en Studie Edisonweg 14c, 1821 BN Alkmaar T:

IMRG Peermap API Documentation V 5.0

Portals and Hosted Files

CMSC434 TUTORIAL #3 HTML CSS JavaScript Jquery Ajax + Google AppEngine Mobile WebApp HTML5

Chapter 2: Interactive Web Applications

Building Ajax Applications with GT.M and EWD. Rob Tweed M/Gateway Developments Ltd

Client-side Web Engineering From HTML to AJAX

Microsoft Advertising adcenter Campaign Analytics Getting Started Guide

DIPLOMA IN WEBDEVELOPMENT

Security Model for the Client-Side Web Application Environments

JAVASCRIPT AND COOKIES

Course Information Course Number: IWT 1229 Course Name: Web Development and Design Foundation

Term Paper. P r o f. D r. E d u a r d H e i n d l. H o c h s c h u l e F u r t w a n g e n U n i v e r s i t y. P r e s e n t e d T o :

What about MongoDB? can req.body.input 0; var date = new Date(); do {curdate = new Date();} while(curdate-date<10000)

A Tale of the Weaknesses of Current Client-side XSS Filtering

Web Programming Step by Step

Blackbox Reversing of XSS Filters

A FRAMEWORK FOR COLLECTING CLIENTSIDE PARADATA IN WEB APPLICATIONS

Team Members: Christopher Copper Philip Eittreim Jeremiah Jekich Andrew Reisdorph. Client: Brian Krzys

10CS73:Web Programming

07/04/2014 NOBIL API. Version 3.0. Skåland Webservice Side 1 / 16

Facebook Twitter YouTube Google Plus Website . o Zooming and Panning. Panel. 3D commands. o Working with Canvas

Google Analytics Social Plug-in Tracking

Are AJAX Applications Vulnerable to Hack Attacks?

NetFlow for SouthWare NetLink

Salesforce Console Integration Toolkit Developer's Guide

Core Ideas CHAPTER 1 PART. CHAPTER 2 Pre-Ajax JavaScript Communications Techniques CHAPTER 3 XMLHttpRequest Object CHAPTER 4 Data Formats

Web Development 1 A4 Project Description Web Architecture

Short notes on webpage programming languages

1. User Guide API overview addon - xml Definition addon.background addon.background.script

Learning Web App Development

Web Development. Owen Sacco. ICS2205/ICS2230 Web Intelligence

AJAX and jmaki for Web 2.0 Development using Java. Inyoung Cho Java Technology Evangelist Sun Microsystems, Inc.

Finding XSS in Real World

WebIOPi. Installation Walk-through Macros

Google Web Toolkit. Progetto di Applicazioni Software a.a. 2011/12. Massimo Mecella

How to Code With MooTools

Vulnerability Scanning of WebApps & Course Reviews Lecture 12

Course Outline Basic Web Development

«W3Schools Home Next Chapter» JavaScript is THE scripting language of the Web.

INTERNET PROGRAMMING AND DEVELOPMENT AEC LEA.BN Course Descriptions & Outcome Competency

Web Development CSE2WD Final Examination June (a) Which organisation is primarily responsible for HTML, CSS and DOM standards?

Introducing Apache Pivot. Greg Brown, Todd Volkert 6/10/2010

An introduction to creating Web 2.0 applications in Rational Application Developer Version 8.0

Cross Site Scripting (XSS) and PHP Security. Anthony Ferrara NYPHP and OWASP Security Series June 30, 2011

NoSQL web apps. w/ MongoDB, Node.js, AngularJS. Dr. Gerd Jungbluth, NoSQL UG Cologne,

Specify the location of an HTML control stored in the application repository. See Using the XPath search method, page 2.

Custom SharePoint Solutions with HTML and JavaScript In this book, you ll learn to: SOURCE CODE ONLINE

Web Same-Origin-Policy Exploration Lab

Web Programming Step by Step

Create interactive web graphics out of your SAS or R datasets

Citrix StoreFront. Customizing the Receiver for Web User Interface Citrix. All rights reserved.

Upgrade to Microsoft Web Applications

Tagging Guide: Website and Implementation. Contents

Homework 3: Component & Interface Design

Lecture 9 Chrome Extensions

J j enterpririse. Oracle Application Express 3. Develop Native Oracle database-centric web applications quickly and easily with Oracle APEX

Visualizing an OrientDB Graph Database with KeyLines

^/ CS> KRIS. JAMSA, PhD, MBA. y» A- JONES & BARTLETT LEARNING

Specific API Usage Limitations... 7 Daily Limitation... 7 Concurrency Limitation... 7 Bulk Use API Description... 8 Site Data API...

Art of Code Front-end Web Development Training Program

Performance Report for: Report generated: Friday, April 24, 2015, 7:29 AM (via API)

Spectrum Technology Platform

The Smart Forms Web Part allows you to quickly add new forms to SharePoint pages, here s how:

Comparison of JavaScript Graph Libraries

DESIGNING HTML HELPERS TO OPTIMIZE WEB APPLICATION DEVELOPMENT

Mobile Web Applications. Gary Dubuque IT Research Architect Department of Revenue

NewsletterAdmin 2.4 Setup Manual

It is highly recommended that you are familiar with HTML and JavaScript before attempting this tutorial.

Security Research Advisory IBM inotes 9 Active Content Filtering Bypass

Developing Web Views for VMware vcenter Orchestrator

AJAX The Future of Web Development?

Transcription:

Javascript Interacting with web pages by Aaron Wheeler (awheeler@yahoo-inc.com) Design Prototyper, Yahoo! Inc.

Schedule of How To: Building Blocks: elements & objects DOM JSON Manipulate elements CSS HTML Events Talk to web services AJAX JSONP Homework

Document Object Model

Document Object Model Humans see web pages as they are displayed on the screen, but browsers see web pages as a structured group of nested page elements (links, paragraphs, divs, etc.). This structured grouping of page elements is called the Document Object Model (DOM).

Document Object Model Traverse elements on the page JS selectors document.getelementbyid document.getelementsbyclassname document.getelementsbytagname CSS selectors id tag class name <div class= content > <h1 id= headertitle > JS History</h1> <p>javascript has a long and illustrious history.</p> <p>here s a taste!</p> </div> In order to change parts of the visible page, we must programatically be able to change parts of the DOM. Javascript and CSS both have support for traversing and referencing parts of the DOM.

Document Object Model document.getelementbyid( headertitle ) Traverse elements on the page JS selectors document.getelementbyid document.getelementsbyclassname document.getelementsbytagname CSS selectors id tag class name <div class= content > <h1 id= headertitle > JS History</h1> <p>javascript has a long and illustrious history.</p> <p>here s a taste!</p> </div>

Document Object Model #headertitle { color:yellow; } Traverse elements on the page JS selectors document.getelementbyid document.getelementsbyclassname document.getelementsbytagname CSS selectors id tag class name <div class= content > <h1 id= headertitle > JS History</h1> <p>javascript has a long and illustrious history.</p> <p>here s a taste!</p> </div>

Document Object Model document.getelementsbyclassname( content ) Traverse elements on the page JS selectors document.getelementbyid document.getelementsbyclassname document.getelementsbytagname CSS selectors id tag class name <div class= content > <h1 id= headertitle > JS History</h1> <p>javascript has a long and illustrious history.</p> <p>here s a taste!</p> </div>

Document Object Model.content { background:black; } Traverse elements on the page JS selectors document.getelementbyid document.getelementsbyclassname document.getelementsbytagname CSS selectors id tag class name <div class= content > <h1 id= headertitle > JS History</h1> <p>javascript has a long and illustrious history.</p> <p>here s a taste!</p> </div>

Document Object Model document.getelementsbytagname( p ) Traverse elements on the page JS selectors document.getelementbyid document.getelementsbyclassname document.getelementsbytagname CSS selectors id tag class name <div class= content > <h1 id= headertitle > JS History</h1> <p>javascript has a long and illustrious history.</p> <p>here s a taste!</p> </div>

Document Object Model p { padding: 0; } Traverse elements on the page JS selectors document.getelementbyid document.getelementsbyclassname document.getelementsbytagname CSS selectors id tag class name <div class= content > <h1 id= headertitle > JS History</h1> <p>javascript has a long and illustrious history.</p> <p>here s a taste!</p> </div>

JSON: JS Object Notation var cornucopia = { corn : [ cob1, cob2, cob3 ], squash : { pumpkin : [...], summer squash : [...], trumpet : [...], }, } leaves : [ redleaf1, orangeleaf2, yellowleafn]

Humans visualize objects as groups or clusters of things. Programatically, Javascript denotes objects using JSON. A Javascript object is basically a group of key-value pairs separated by a colon. A key can be a string or a literal, and the value can be any valid Javascript (variable reference, string, integer, boolean, null, function, etc.) JSON: JS Object Notation var cornucopia = { corn : [ cob1, cob2, cob3 ], squash : { pumpkin : [...], summer squash : [...], trumpet : [...], }, } leaves : [ redleaf1, orangeleaf2, yellowleafn]

Humans visualize objects as groups or clusters of things. Programatically, Javascript denotes objects using JSON. A Javascript object is basically a group of key-value pairs separated by a colon. A key can be a string or a literal, and the value can be any valid Javascript (variable reference, string, integer, boolean, null, function, etc.) JSON: JS Object Notation Key-Value Pairs Keys are strings or plain text Values are JS var cornucopia = { corn : [ cob1, cob2, cob3 ], squash : { pumpkin : [...], summer squash : [...], trumpet : [...], }, } leaves : [ redleaf1, orangeleaf2, yellowleafn]

JSON: JS Object Notation var myobject = { key1 : value1, sum : 1+1, fn : function(){return x }, array: [ a, b, c ] };

JSON: JS Object Notation // reference keys with dot-notation myobject.key1 // => value1 var myobject = { key1 : value1, sum : 1+1, fn : function(){return x }, array: [ a, b, c ] };

JSON: JS Object Notation // or reference keys with array-notation myobject[ key1 ] // => value1 var myobject = { key1 : value1, sum : 1+1, fn : function(){return x }, array: [ a, b, c ] };

JSON: JS Object Notation // values are evaluated myobject[ sum ] // => 2 var myobject = { key1 : value1, sum : 1+1, fn : function(){return x }, array: [ a, b, c ] };

JSON: JS Object Notation // Functions can conveniently be stored myobject[ fn ]() // => x var myobject = { key1 : value1, sum : 1+1, fn : function(){return x }, array: [ a, b, c ] };

JSON: JS Object Notation // keys need not be strings myobject.array[0] // => a var myobject = { key1 : value1, sum : 1+1, fn : function(){return x }, array: [ a, b, c ] };

JSON: JS Object Notation // but keys can be referenced as strings myobject[ array ][1] // => b var myobject = { key1 : value1, sum : 1+1, fn : function(){return x }, array: [ a, b, c ] };

Manipulation

Manipulation In order to manipulate the visible page, we have to change the DOM. Two common ways to do this are to change CSS classes and HTML in the DOM with Javascript. In order to execute the Javascript, we leverage user events.

Manipulation CSS - toggle CSS class names - add class name - remove class name HTML - innerhtml - change HTML - append HTML <div class= content > <h1 id= headertitle > JS History</h1> <p>javascript has a long and illustrious history.</p> <p>here s a taste!</p> </div> <script> var h = document. getelementbyid( js_title ); </script>

Manipulation: CSS h.classname = highlight CSS - toggle CSS class names - add class name - remove class name HTML - innerhtml - change HTML - append HTML <div class= content > <h1 id= headertitle class= highlight > JS History</h1> <p>javascript has...</p> </div> <script> var h = document. getelementbyid( headertitle ); </script>

Manipulation: CSS h.classname = h.classname. replace(/(^ )content( $)/, ) CSS - toggle CSS class names - add class name - remove class name HTML - innerhtml - change HTML - append HTML <div class= > <h1 id= headertitle > JS History</h1> <p>javascript has...</p> </div> <script> var h = document. getelementbyid( headertitle ); </script>

Manipulation: HTML h.innerhtml = Javascript CSS - toggle CSS class names - add class name - remove class name HTML - innerhtml - change HTML - append HTML <div class= content > <h1 id= headertitle > Javascript</h1> <p>javascript has...</p> </div> <script> var h = document. getelementbyid( headertitle ); </script>

Manipulation: HTML h.innerhtml += <em>over the ages</em> CSS - toggle CSS class names - add class name - remove class name HTML - innerhtml - change HTML - append HTML <div class= content > <h1 id= headertitle > JS History <em>over the ages</em> </h1> <p>javascript has...</p> </div> <script> var h = document. getelementbyid( headertitle ); </script>

Manipulation: Events CSS - :hover HTML + Javascript - onhover - onmouseover / onmouseout - onmouseclick - onfocus / onblur - onload <div class= content > <h1 id= headertitle > JS History</h1> <p>javascript has...</p> </div>

Manipulation: Events CSS - :hover HTML + Javascript - onhover - onmouseover / onmouseout - onmouseclick - onfocus / onblur - onload <style> h1 { color:white; } h1:hover { color:pink; } </style> <div class= content > <h1 id= headertitle > JS History</h1> <p>javascript has...</p> </div>

Manipulation: Events CSS - :hover HTML + Javascript - onhover - onmouseover / onmouseout - onclick - onfocus / onblur - onload <script> function add(elt) { elt.innerhtml = parseint(elt.innerhtml)+1; } </script> <div class= content > <h1 id= headertitle > JS History</h1> <p onclick= add(this); > 0</p> </div>

Manipulation: Events CSS - :hover HTML + Javascript - onhover - onmouseover / onmouseout - onclick - onfocus / onblur - onload <script> function add(elt) { elt.innerhtml = parseint(elt.innerhtml)+1; } </script> <div class= content > <h1 id= headertitle > JS History</h1> <p onclick= add(this); > 1</p> </div>

Manipulation: Events CSS - :hover HTML + Javascript - onhover - onmouseover / onmouseout - onclick - onfocus / onblur - onload <script> function add(elt) { elt.innerhtml = parseint(elt.innerhtml)+1; } </script> <div class= content > <h1 id= headertitle > JS History</h1> <p onclick= add(this); > 2</p> </div>

Talking to the Web Web App Internet AJAX Web 2.0 introduced asynchronous ways of talking to the web via AJAX. This spurred a revolution in web apps, but had some shortcomings.

Talking to the Web JSONP YQL (think babelfish) As web apps matured, so did the means for talking to the web. JSONP is a cross-domain method for talking to supporting web APIs, and YQL is a way for talking to these APIs.

Talking to the Web AJAX - Asynchronous Javascript XML - Limited to same-domain communication JSONP - JSON with Padding - work-around for cross-site JS loading YQL - Yahoo! Query Language - Standardize way to talk to web APIs Asynchronous behavior Two or more things happen concurrently (aka threading) Callback functions Provide direction on what to do once an asynchronous call (thread) completes.

Talking to the Web AJAX - Asynchronous Javascript XML - Limited to same-domain communication JSONP - JSON with Padding - work-around for cross-site JS loading Leverages Javascript function XMLHTTPRequest Cannot load data from third-party domains YQL - Yahoo! Query Language - Standardize way to talk to web APIs

Talking to the Web AJAX - Asynchronous Javascript XML - Limited to same-domain communication JSONP - JSON with Padding - work-around for cross-site JS loading YQL - Yahoo! Query Language - Standardize way to talk to web APIs Calls third-party domains by injecting a <script> tag into the document. Response is wrapped in a function call. <!-- responds with cb({flickrpics:[]}) --> <script src= http:// flickr.com/ popular.json?cbfunc=cb > </script> <script> function cb(dat) {...}

Talking to the Web AJAX - Asynchronous Javascript XML - Limited to same-domain communication JSONP - JSON with Padding - work-around for cross-site JS loading YQL - Yahoo! Query Language - Standardize way to talk to web APIs var query = select * from search.web where query = dogs ; function callback(data) { alert( got data! ); console.log(data); } // YQL is a custom class // in Homework #3 YQL.query(query, callback );

Homework Create clickable tabs http://jsfiddle.net/4r6k3/ Track history of tab clicks http://jsfiddle.net/ajknm/ Tabbed access to faceted web search http://jsfiddle.net/gmmcc/ Solutions for all homework can be found by appending 1 to the URL. For example, the solution to the first homework can be found at http://jsfiddle.net/4r6k3/1