UNIT 6 JAVASCRIPT EVENT HANDLERS &WEB BROWSERS DETECTION.

Slides:



Advertisements
Similar presentations
Chapter 08: Adding Adding Interactivity Interactivity With With Behaviors Behaviors By Bill Bennett Associate Professor MSJC CIS MVC.
Advertisements

Bring Life to Your Web Pages with JavaScript and HTML5 Ole Ildsgaard Hougaard -
Computer and Communication Fundamental Basic web programming Lecture 8 Rina Zviel-Girshin.
JavaScript and the DOM Les Carr COMP3001 Les Carr COMP3001.
Georgia Institute of Technology JavaScript part 2 Barb Ericson Georgia Institute of Technology May 2006.
JavaScript (Part 2) CS 183 4/13/2010. JavaScript (Part 2) Will cover: ◦ For.. In ◦ Events ◦ Try.. Catch, Throw ◦ Objects.
NAMEd anchors Enabling users to jump to specific points within Web documents.
Chapter 7 © 2001 by Addison Wesley Longman, Inc. 1 Chapter 7 Sebesta: Programming the World Wide Web.
JavaScript: Introduction to Handling Events 20 th April 2011.
20-Jun-15 JavaScript and HTML Simple Event Handling.
JavaScript 101 Lesson 5: Introduction to Events. Lesson Topics Event driven programming Events and event handlers The onClick event handler for hyperlinks.
Lesson 2 Event Handling. Object Event Handlers Most of the objects that make up the Document Object Model respond to asynchronous, user generated events.
JavaScript Client Side scripting. Client-side Scripts Client-side scripts, which run on the user’s workstation can be used to: Validate user inputs entered.
CP476 Internet Computing JavaScript and HTML1 1.JavaScript Execution Environment The JavaScript Window object represents the window in which the browser.
JS: DOM Form Form Object Form Object –The Form object represents an HTML form. –For each instance of a tag in an HTML document, a Form object is created.
HTML Forms/Events (Instructor Lesson) The Event model HTML Forms Custom Events 1.
CNIT 133 Interactive Web Pags – JavaScript and AJAX Event and Event Handling.
Event Handlers CS101 Introduction to Computing. Learning Goals Learn about event handlers Determine how events are useful in JavaScript Discover where.
Chapter 19: Adding JavaScript
JavaScript II ECT 270 Robin Burke. Outline JavaScript review Processing Syntax Events and event handling Form validation.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
Internet Mark-up Languages CO32036 Part Lecture: Elementary JavaScript.
CSS Class 7 Add JavaScript to your page Add event handlers Validate a form Open a new window Hide and show elements Swap images Debug JavaScript.
Lesson13. JavaScript JavaScript is an interpreted language, designed to function within a web browser. It can also be used on the server.
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
CO1552 Web Application Development HTML Forms, Events and an introduction to JavaScript.
DOM Events. JS Events Outline About Events – Introduction – Registering events – Getting information from events Event order/phases – Preventing default.
Intro to JavaScript Scripting language –ECMAScript compliant –Client side vs. server side Syntactic rules –White space –Statement end: ; optional –Comments:
Lecture 10 JavaScript: DOM and Dynamic HTML Boriana Koleva Room: C54
Introduction to the Document Object Model DOM *Understand document structure manipulation *Dynamic effects in web pages *Programming, scripting, web content.
Scott Marino MSMIS Summer Session Web Site Design and Authoring Session 8 Scott Marino.
Event JavaScript's interaction with HTML is handled through events that occur when the user or browser manipulates a page. When the page loads, that is.
By Tharith Sriv. To write a web page you use: HHTML (HyperText Markup Language), AASP (Active Server Page), PPHP (HyperText Preprocessor), JJavaScript,
Thursday, August 6 th, 2015 Instructor: Craig Duckett Event Handling.
Jaana Holvikivi 1 Introduction to Javascript Jaana Holvikivi Metropolia.
1 CSC160 Chapter 7: Events and Event Handlers. 2 Outline Event and event handlers onClick event handler onMouseOver event handler onMouseOut event handler.
Event Handling. Objectives Using event handlers Simulating events Using event-related methods.
Project 8: Reacting to Events Essentials for Design JavaScript Level One Michael Brooks.
COS 125 DAY 20. Agenda Assignment 8 not corrected yet Assignment 9 posted  Due April 16 New course time line Discussion on Scripts 
Web Programming Java Script & jQuery Web Programming.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 7 TH EDITION Chapter 14 Key Concepts 1 Copyright © Terry Felke-Morris.
5 th and 4 th ed: some from chapters 9, 12, 13 SY306 Web and Databases for Cyber Operations Slide Set #8: Dynamic HTML.
7. JavaScript Events. 2 Motto: Do you think I can listen all day to such stuff? –Lewis Carroll.
JS DOM. Introduction An HTML page is rendered (painted) in a browser The browser assembles all the elements (objects) contained in the HTML page To create.
Document Object Model Nasrullah. DOM When a page is loaded,browser creates a Document Object Model of the Page.
JavaScript II ECT 270 Robin Burke. Outline Functions Events and event handling Form validation.
JavaScript Events.
JavaScript Event Handlers. Introduction An event handler executes a segment of a code based on certain events occurring within the application, such as.
LESSON : EVENTS AND FORM VALIDATION -JAVASCRIPT. EVENTS CLICK.
Event Handlers Events are asynchronous. When an event occurs, JavaScript can execute code in response to the user’s action. This response to the user-initiated.
JavaScript and Ajax (JavaScript Environment) Week 6 Web site:
Functions Wouldn’t it be nice to be able to bring up a new animal and paragraph without having to reload the page each time? We can! We can place the.
SE-2840 Dr. Mark L. Hornick 1 Dynamic HTML Handling events from DOM objects.
Methods and Object Information. Some Document Methods.
JavaScript and HTML Simple Event Handling 11-May-18.
Web Development & Design Foundations with HTML5 7th Edition
JAVASCRIPTS AND HTML DOCUMENTS
JavaScript and HTML Simple Event Handling 19-Sep-18.
JavaScript Events.
DHTML Javascript Internet Technology.
DHTML Javascript Internet Technology.
Functions, Regular expressions and Events
JavaScript and Ajax (JavaScript Events)
JAVA SCRIPT OBJECTS & DOM
Web Programming and Design
Web Programming and Design
Web Programming and Design
JavaScript and HTML Simple Event Handling 26-Aug-19.
JavaScript and HTML Simple Event Handling 4-Oct-19.
Presentation transcript:

UNIT 6 JAVASCRIPT EVENT HANDLERS &WEB BROWSERS DETECTION

OBJECTIVES  CO3 Create a website that is optimized for viewing on a mobile device.  CO5 Describe the use of scripting when creating a website.  CO6 Create a dynamic website using JavaScript. 2

LEARNING OUTCOMES LO30 Describe how JavaScript event handlers work. LO31 Create JavaScript event handlers. LO32 Explain various methods of determining which features a browser supports. LO33 Explain what is meant by "graceful degradation." LO34Identify the steps you should take to test a mobile website. 3

DOM EVENTS DOM events are things that happen to the browser. For instance:  When a user clicks the mouse  When a web page has loaded  When an image has been loaded  When the mouse moves over an element  When an input field is changed  When an HTML form is submitted  When a user strokes a key 4

DOM EVENTS  Mouse Events: onclick, ondblclick, onmousedown, onmousemove, onmouseover, onmouseout, onmouseup  Keyboard Events: onkeydown, onkeypress, onkeyup  Object Events: onabort, onerror, onload, onresize, onscroll, onunload  Form Events: onblur, onchange, onfocus, onreset, onselect, onsubmit 5

JAVASCRIPT EVENT HANDLERS  The script or function that you use to detect and respond to a DOM event is called an event handler.  The basic syntax of event handlers is: name_of_handler = "JavaScript code here" i.e. onclick = "alert('Hello World!');"  Create an event handler with no tag: <a href=" onmouseover="alert('You moved over the link.');"> This is a link. 6

JAVASCRIPT EVENT HANDLERS Create an event handler with tag: function DoIt() { alert("You moved over the link."); } This is a link. 7

 event.button  event.clientX  event.clientY  event.altkey  event.ctrlkey  event.shiftkey  event.keycode  event.srcElement 8 INTERNET EXPLORER EVENT PROPERTIES

 event.modifiers  event.pageX  event.pageY  event.which  event.button  event.target 9 NON- INTERNET EXPLORER EVENT PROPERTIES

USING MOUSE EVENTS JavaScript can detect mouse actions. Mouse event handlers:  Use onClick when the mouse button is clicked on images, buttons, links, etc.  Use onDblClick when the mouse button is double-clicked on images, buttons, etc., but not links  Use onMouseOver and onMouseOut to create rollover images  Use onMouseDown when the user presses the mouse button  Use onMouseUp when the user releases the mouse button 10

EXAMPLE OF MOUSE CLICK TEST 11

USING KEYBOARD EVENTS JavaScript can detect keyboard actions. Keyboard event handlers:  onKeyPress, onKeyDown, onKeyUp Display typed characters  Use event.keyCode property for IE i.e. key = String.fromCharCode(event.keyCode)  Use event.which property for non-IE i.e. key = String.fromCharCode(event.which) 12

EXAMPLE OF DISPLAYING TYPED CHARACTERS 13

USING THE ONLOAD AND ONUNLOAD EVENTS  onLoad event occurs when the current page or images finish loading from the server. i.e.  onUnload event occurs when another page is loaded or when the browser window is closed. i.e. 14

USING ONCLICK TO HIDE AND SHOW CONTENT 15

USING ONCLICK TO HIDE AND SHOW CONTENT 16

USING ONCLICK TO HIDE AND SHOW CONTENT 17

HTML5 SUPPORT AND CSS3 SUPPORT  HTML5 and CSS3 are a giant collection of specifications, standards, and tools that are wrapped up together under the title HTML5.  No web browser supports all the HTML5 standards.  Only IE 9 or later supports HTML5.  Opera Mobile has the most HTML5 support of mobile browsers.  Desktop browsers have more HTML5 support than mobile browsers. 18

19 HTML5 SUPPORT AND CSS3 SUPPORT

DETECTING HTML5 SUPPORT  It is a bad idea to detect mobile browsers or devices for HTML5 development,i.e.: Some browsers send user agent strings that imply they are a different browser. Privacy software can cloak the user agent string. Browser features can change while the user agent stays the same.  Instead, you should try detecting the HTML5 features you want to use. 20

DETECTING HTML5 SUPPORT The four basic ways to detect for HTML5 functions are to:  Check for the property on a global object.  Check for the property on an element you create.  Check that a method returns a correct value.  Check that an element retains a value. 21

DETECTING HTML5 SUPPORT  Check for the property on a global object.  Every HTML5 document is displayed in a global element – the navigator or the window.  For example, to test for offline web applications: if (window.applicationCache){ document.write("Yes, your browser can use offline web applications."); }else{ document.write("No, your browser cannot use offline web applications."); } 22

DETECTING HTML5 SUPPORT  Check for the property on an element you create.  When you create an element in the DOM, you are really just creating a dummy element in your browser's memory. 23

DETECTING HTML5 SUPPORT For example, to test if the browser support tag: if (document.createElement('canvas').getContext){ document.write("Yes, your browser can use the <canvas> tag."); } else{ document.write("No, your browser cannot use the <canvas> tag."); } 24

CHECK THAT A METHOD RETURNS A CORRECT VALUE. You can check that a method returns a correct value to validate elements like and that have codecs that are supported differently. The primary codecs are WebM and H.264. For example: return !!document.createElement('video').canPlayType; !video.canPlayType('video/mp4; codecs="avc1.42E01E, mp4a.40.2"'); 25

CHECK THAT AN ELEMENT RETAINS A VALUE  This is the most complicated way to check for HTML5 support.  This is an important testing method to learn because it is used to test for many different HTML5 features. 26

CHECK THAT AN ELEMENT RETAINS A VALUE For example to test whether the browser supports the range input element: function rangeCheck(){ var i = document.createElement("input"); i.setAttribute("type", "range"); if (i.type == "text"){ document.write("not"); } return; } 27

GRACEFUL DEGRADATION  Internet Explorer is the only exception to the rule about not detecting browsers.  To support HTML5 in IE 8, 7, and 6, add the HTMLshiv script to the section: 28

GRACEFUL DEGRADATION  Note the HTML5shiv script doesn't add functionality of the HTML5 tags to IE 6, 7, and 8, just allows the browser to recognize the HTML5 tags.  The idea of grace degradation is that a system should continue to function even if one if more of its components fails. 29

GRACEFUL DEGRADATION The secret to graceful degradation is making good choices. 1.Choose what technology your HTML5 application is going to support for the best features. 2.Decide which features are absolutely critical to the app's functionality. 3.Draw up a fallback plan for your core features. 4.Finally, come up with fallback options for your best features. 30

USING CSS3 MEDIA QUERIES TO DETECT MOBILE BROWSERS  all  aural  braille  embossed  handheld  print  projection  screen  tty  tv 31 CSS2 media-dependent style sheets to allow separate style sheets for different types of media i.e.

USING CSS3 MEDIA QUERIES TO DETECT MOBILE BROWSERS CSS3 extends the media attributes to allow you to check the user agent against various conditions, i.e.:  Width and height of both the screen and the device  Orientation of the screen  Aspect ratio of the screen and device  Colors, including number of colors, whether monochrome or color, and the color bit depth  Resolution  Scanning process of TV devices  Grid or bitmap devices 32