Interacting with a Web Page using JavaScript Mat Kelly GTAI Presentation January 10, 2014.

Slides:



Advertisements
Similar presentations
Samsung Smart TV is a web-based application running on an application engine installed on digital TVs connected to the Internet.
Advertisements

Authoring Languages and Web Authoring Software 4.01 Examine web page development and design.
JQUERY/AJAX ALIREZA KHATAMIAN DELARAM YAZDANSEPAS.
The Web Warrior Guide to Web Design Technologies
1 Lesson 10 Using JavaScript with Styles HTML and JavaScript BASICS, 4 th Edition Barksdale / Turner.
CM143 - Web Week 2 Basic HTML. Links and Image Tags.
Agenda What is AJAX? What is jQuery? Demonstration/Tutorial Resources Q&A.
JQuery CS 268. What is jQuery? From their web site:
CGS3066: Web Programming and Design Summer 2014 Instructor Mir Anamul Hasan.
JavaScript Teppo Räisänen LIIKE/OAMK HTML, CSS, JavaScript HTML defines the structure CSS defines the layout JavaScript is used for scripting It.
DOM and JavaScript Aryo Pinandito.
DHTML: Dynamic HTML Internet Technology1. What is DHTML? A collection of enhancements to HTML ► To create dynamic and interactive websites Combination.
Title, meta, link, script.  The title looks like:  The tag defines the title of the document in the browser toolbar.  It also: ◦ Provides a title for.
SEG3210 DHTML Tutorial. DHTML DHTML is a combination of technologies used to create dynamic and interactive Web sites. –HTML - For creating text and image.
Lab 3: Language Structures User Interface Lab: GUI Lab Sep. 9 th, 2014.
Working with Objects Creating a Dynamic Web Page.
CITS1231 Web Technologies JavaScript and Document Object Model.
HTML, XHTML, and CSS Sixth Edition Chapter 1 Introduction to HTML, XHTML, and CSS.
JavaScript, Fourth Edition
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
Javascript II DOM & JSON. In an effort to create increasingly interactive experiences on the web, programmers wanted access to the functionality of browsers.
Client-Side Scripting JavaScript.  produced by Netscape for use within HTML Web pages.  built into all the major modern browsers. properties  lightweight,
Copyright 2007, Information Builders. Slide 1 Understanding Basic HTML Amanda Regan Technical Director June, 2008.
Web Design (1) Terminology. Coding ‘languages’ (1) HTML - Hypertext Markup Language - describes the content of a web page CSS - Cascading Style Sheets.
JQuery Introduction © Copyright 2014, Fred McClurg All Rights Reserved.
DYNAMIC HTML What is Dynamic HTML: HTML code that allow you to change/ specify the style of your web pages. Example: specify style sheet, object model.
Unleash the Power of jQuery Learning & Development Team Telerik Software Academy.
1 Javascript DOM Peter Atkinson. 2 Objectives Understand the nature and structure of the DOM Add and remove content from the page Access and change element.
Advanced DOM Builds on last presentation on DOM Allows you to dynamically create elements and position them on a page DOM methods/properties are W3C standard.
JQuery JavaScript is a powerful language but it is not always easy to work with. jQuery is a JavaScript library that helps with: – HTML document traversal.
4.01B Authoring Languages and Web Authoring Software 4.01 Examine webpage development and design.
INTRODUCTION JavaScript can make websites more interactive, interesting, and user-friendly.
Invitation to Computer Science 6 th Edition Chapter 10 The Tower of Babel.
Dave Salinas. What is XML? XML stands for eXtensible Markup Language Markup language, like HTML HTML was designed to display data, whereas XML was designed.
Document Object Model Nasrullah. DOM When a page is loaded,browser creates a Document Object Model of the Page.
JavaScript Introduction and Background. 2 Web languages Three formal languages HTML JavaScript CSS Three different tasks Document description Client-side.
Practice for Chapter 3: Assume that you are a freelance web designer and need to create a website to promote your freelance company.
Introduction to JavaScript LIS390W1A Web Technologies and Techniques 24 Oct M. Cameron Jones.
Chapter 10 Dynamic HTML (DHTML) JavaScript, Third Edition.
XML DOM Week 11 Web site:
Source of website: “Text/css rel=“styles heet” This is an external style sheet link. This means that the.
Week-12 (Lecture-1) Cascading Style Sheets (CSS): describe how documents are presented on screens. Types of Style Sheets: External Style Sheet - Define.
JQuery Fundamentals Introduction Tutorial Videos
Web Basics: HTML/CSS/JavaScript What are they?
Project 1 Introduction to HTML.
Programming Web Pages with JavaScript
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Introduction to Dynamic Web Programming
JavaScript Event Handling.
W3C Web standards and Recommendations
Introduction to Web programming
Prepared for Md. Zakir Hossain Lecturer, CSE, DUET Prepared by Miton Chandra Datta
Introduction to Internet Programming
DHTML Javascript Internet Technology.
jQuery The Easy JavaScript Nikolay Chochev Technical Trainer
Introduction to Web Page Design
JQuery with ASP.NET.
DHTML Javascript Internet Technology.
Introduction to Programming the WWW I
Working with Dynamic Content and Styles
E-commerce Applications Development
Web-Applications & AJAX
HTML and CSS Basics.
Introduction to Web Application Design
Web Programming and Design
Week 5: Recap and Portfolio Site
Creating dynamic/interactive web pages
Web Programming and Design
Web Programming and Design
Presentation transcript:

Interacting with a Web Page using JavaScript Mat Kelly GTAI Presentation January 10, 2014

What’s in a Web Page Three languages make up a web page – HTML – HyperText Markup Language Defines web page STRUCTURE & CONTENT – CSS – Cascading Style Sheets Defines web page STYLE – JavaScript (JS) Defines web page BEHAVIOR 2

What’s in a Web Page Three languages make up a web page – HTML – HyperText Markup Language Defines web page STRUCTURE & CONTENT – CSS – Cascading Style Sheets Defines web page STYLE – JavaScript (JS) Defines web page BEHAVIOR 3

Behavior? Web pages can be made up of only content – HTML w/o style (CSS) or behavior (JS) Interaction and animation requires the definition of functionality – CSS has limited control Simpler animation (hovers) and effects – JavaScript can create, remove and manipulate content! 4

How can I do this? Within a web page’s source: Content! index.html 5

How can I do this? Within a web page’s source: Content! index.html 6 HTML files can be Rendered in a browser

How can I do this? Within a web page’s source: – Define scripts inline // Code goes here Content! index.html 7

How can I do this? Within a web page’s source: – Define scripts inline – Include external scripts // Code goes here Content! index.html 8 window.onload = function(){ var b = document.getElementsByTagName(“body”); var myBody = b[0]; var newText = document.createTextNode(“New!”); myBody.appendChild(newText); }; code.js

How can I do this? Within a web page’s source: – Define scripts inline – Include external scripts Define functionality elsewhere // Code goes here Content! index.html window.onload = function(){ var b = document.getElementsByTagName(“body”); var myBody = b[0]; var newText = document.createTextNode(“New!”); myBody.appendChild(newText); }; code.js 9

Deconstructing the code Line by line End-result: we’ll modify this page  using this code. window.onload = function(){ var b = document.getElementsByTagName(“body”); var myBody = b[0]; var newText = document.createTextNode(“New!”); myBody.appendChild(newText); }; code.js 10 

Acquiring a browser event window.load : when the page has finished loading, do something – JS libraries exist for cross-browser compatibility – Simplified for this example window.onload = function(){ var b = document.getElementsByTagName(“body”); var myBody = b[0]; var newText = document.createTextNode(“New!”); myBody.appendChild(newText); }; code.js 11

Associating with the browser event = Assigns something (variable or function) to the onload event window.onload = function(){ var b = document.getElementsByTagName(“body”); var myBody = b[0]; var newText = document.createTextNode(“New!”); myBody.appendChild(newText); }; code.js 12

Providing a wrapper for our event definition function(){…} :Defines the function to be assigned Closing ; required to be syntactically correct window.onload = function(){ var b = document.getElementsByTagName(“body”); var myBody = b[0]; var newText = document.createTextNode(“New!”); myBody.appendChild(newText); }; code.js 13

Querying the web page var b = document.getElementsByTagName(“body”); Asks the document, “Give me all of your body tags and assign the set to variable b” Any HTML tag can be queried this way window.onload = function(){ var b = document.getElementsByTagName(“body”); var myBody = b[0]; var newText = document.createTextNode(“New!”); myBody.appendChild(newText); }; code.js 14 …

Isolating the content we want From the collection of body tags, give me the first element (JS is index base 0) window.onload = function(){ var b = document.getElementsByTagName(“body”); var myBody = b[0]; var newText = document.createTextNode(“New!”); myBody.appendChild(newText); }; code.js 15 myBody … points to our page from before var myBody = b[0];

Creating Content! Create a new text node, store in a variable This DOES NOT yet add the node to the webpage window.onload = function(){ var b = document.getElementsByTagName(“body”); var myBody = b[0]; var newText = document.createTextNode(“New!”); myBody.appendChild(newText); }; code.js 16 “New!” var newText = document.createTextNode(“New!”);

Attaching our created content! Finally, append the new node to the first body tag window.onload = function(){ var b = document.getElementsByTagName(“body”); var myBody = b[0]; var newText = document.createTextNode(“New!”); myBody.appendChild(newText); }; code.js 17 “New!” Content has been added to the webpage using JavaScript! myBody.appendChild(newText);

This has been done before, Use a Library window.onload = function(){ var b = document.getElementsByTagName(“body”); var myBody = b[0]; var newText = document.createTextNode(“New!”); myBody.appendChild(newText); }; $(document).ready(function(){ $(“body”)[0].append(“New!”); }); code.js easyCode.js 18

Beyond just adding text Adding content from elsewhere – AJAX: Asynchronous JavaScript and XML $.ajax({ url: “newContent.xml”}).done(function(data){ $(“body”)[0].append(data); }); Giving user input feedback var myAge = document.getElementById(“age”).value; if(myAge.length == 0){ $(“p”).append(“You forgot your age!”); } 19

Beyond just adding text Adding content from elsewhere – AJAX: Asynchronous JavaScript and XML $.ajax({ url: “newContent.xml”}).done(function(data){ $(“body”)[0].append(data); }); Giving user input feedback 20 var myAge = document.getElementById(“age”).value; if(myAge.length == 0){ $(“p”).append(“You forgot your age!”); } THIS IS JUST THE BEGINNING!

Summary JavaScript can: – control behavior of a web page – be loaded inline or externally – manipulate web page contents – acts as a functional bridge between a browser and a web page 21