SlideShare a Scribd company logo
1 of 19
JavaScript: 
Events and Events Handling 
Yuriy Bezgachnyuk 
August, 2014
Special Thanks 
to John Resig
Agenda 
▪Events 
– What is event 
– Phases of event 
– How to handle events 
– Event Object 
– Keyboard and mouse events 
▪Exception handling
Events 
▪Event – an action that is fired (initiated) 
within a web page. 
▪JavaScript is Single Thread 
▪JavaScript uses asynchronous callback
Phases of Event 
▪Phase #1 – Capturing 
▪Phase #2 – Bubbling
Defining Event Handler 
▪Old way 
window.onload = function() {}; 
▪New way (add event) 
window.addEventListener(”load”,func,false) 
window.attachEvent(”onload”,func); // IE < 9 
▪We can define event handler only for 
objects!!!
The Event Object 
▪Contains contextual information about the 
current event 
▪An object that’s provided, or is available, 
inside of every event handler function 
▪W3C Standard Browser: e 
▪Internet Explorer: window.event
Cancel Bubbling 
▪Since you know how event 
capturing/bubbling works, let’s explore 
how you can take control it. 
▪W3C 
– e.stopPropagation() 
▪IE 
– window.event.cancelBubble 
▪Live Example (Thanks for J. Resig )
Cancel Bubbling (Scheme)
Cancel Bubbling (Code + Live) 
function stopBuuble(e) { 
if (e && e.stopPropagation) { 
e.stopPropagation(); 
} 
else { 
window.event.cancelBubble = true; 
} 
} var all = document.getElementsByTagName("*"); 
for (var i = 0;i < all.length;i++) { 
all[i].onmouseover = function(e) { 
this.style.border = "1px solid red"; 
stopBuuble(e); 
}; 
all[i].onmouseout = function(e) { 
this.style.border = "0px"; 
stopBuuble(e); 
}; 
}
Overriding Browser Default Event 
▪For most events that take place, the 
browser has some default action that will 
always occur. 
– For example, clicking an <a> element will take 
you to its associated web page; this is a default 
action in the browser. This action will always 
occur after both the capturing and the 
bubbling event phases
Overriding {code: true, live:true} 
function stopDefault(e) { 
if (e && e.preventDefault) { 
e.preventDefault(); 
} 
else { 
window.event.returnValue = false; 
} 
} var iframe = document.getElementById("iframe"); 
var a = document.getElementsByTagName("a"); 
for (var i = 0;i < a.length;i++) { 
a[i].onclick = function(e) { 
iframe.src = this.href; 
return stopDefault(e); 
}; 
}
Keyboard and Mouse Events 
▪Mouse Events 
– onMouseDown 
– onMouseMove 
– onMouseOut 
– onMouseOver 
– onMouseUp 
– onClick 
– onDblClick 
– onDragDrop 
▪Keyboard Events 
– onKeyDown 
– onKeyPress 
– onKeyUp
Practice: Handling Mouse events 
▪Task: <div> container must change 
bg-color after some mouse event 
– hover => yellow; 
– click => red; 
– dblclick =>blue; 
– out =>white;
Code 
<body> 
<div id="container"> 
</div> 
<script type="text/javascript"> 
var div_c = document.getElementById("container"); 
div_c.addEventListener("mouseover", a, false); 
div_c.addEventListener("mouseout", b, false); 
div_c.addEventListener("click", c, false); 
div_c.addEventListener("dblclick", d, false); 
</script> 
</body> 
... 
function a() 
{ 
div_c.style.backgroundColor = "yellow"; 
}
Keyboard Events Handling 
▪Let’s investigate little part of code 
<script type="text/javascript"> 
window.addEventListener("keydown", handleEvent, false); 
window.addEventListener("keypress", handleEvent, false); 
window.addEventListener("keyup", handleEvent, false); 
</script> 
<script type="text/javascript"> 
function handleEvent(e) { 
var e = e || window.event; 
console.log(e); 
} 
</script>
And so what we have…? 
▪After investigation previous slide we can 
see next features of KB events: 
– keydown  keypress  keyup (sequence of 
KB events!!!) 
– Some KB events have value (not 0) of property 
charCode (keypress event only). 
– keydown and keyup events generate scan-code 
only (keyCode property) which always 
similar and don’t depends on KB layout!!!
References and sources 
1. John Resig Pro JavaScript Techniques 
2. David Flenagan JavaScript 
3. Christian Wenz JavaScript Phrasebook 
4. https://developer.mozilla.org/
Questions?

More Related Content

What's hot

Lab #2: Introduction to Javascript
Lab #2: Introduction to JavascriptLab #2: Introduction to Javascript
Lab #2: Introduction to JavascriptWalid Ashraf
 
JavaScript - Chapter 4 - Types and Statements
 JavaScript - Chapter 4 - Types and Statements JavaScript - Chapter 4 - Types and Statements
JavaScript - Chapter 4 - Types and StatementsWebStackAcademy
 
Intro to Asynchronous Javascript
Intro to Asynchronous JavascriptIntro to Asynchronous Javascript
Intro to Asynchronous JavascriptGarrett Welson
 
JavaScript: Variables and Functions
JavaScript: Variables and FunctionsJavaScript: Variables and Functions
JavaScript: Variables and FunctionsJussi Pohjolainen
 
JavaScript - Chapter 6 - Basic Functions
 JavaScript - Chapter 6 - Basic Functions JavaScript - Chapter 6 - Basic Functions
JavaScript - Chapter 6 - Basic FunctionsWebStackAcademy
 
Java script errors &amp; exceptions handling
Java script  errors &amp; exceptions handlingJava script  errors &amp; exceptions handling
Java script errors &amp; exceptions handlingAbhishekMondal42
 
JavaScript - Chapter 11 - Events
 JavaScript - Chapter 11 - Events  JavaScript - Chapter 11 - Events
JavaScript - Chapter 11 - Events WebStackAcademy
 
Form using html and java script validation
Form using html and java script validationForm using html and java script validation
Form using html and java script validationMaitree Patel
 
스프링 시큐리티 구조 이해
스프링 시큐리티 구조 이해스프링 시큐리티 구조 이해
스프링 시큐리티 구조 이해beom kyun choi
 
JavaScript - An Introduction
JavaScript - An IntroductionJavaScript - An Introduction
JavaScript - An IntroductionManvendra Singh
 

What's hot (20)

Javascript functions
Javascript functionsJavascript functions
Javascript functions
 
Javascript
JavascriptJavascript
Javascript
 
Lab #2: Introduction to Javascript
Lab #2: Introduction to JavascriptLab #2: Introduction to Javascript
Lab #2: Introduction to Javascript
 
Javascript 101
Javascript 101Javascript 101
Javascript 101
 
jQuery
jQueryjQuery
jQuery
 
JavaScript - Chapter 4 - Types and Statements
 JavaScript - Chapter 4 - Types and Statements JavaScript - Chapter 4 - Types and Statements
JavaScript - Chapter 4 - Types and Statements
 
Intro to Asynchronous Javascript
Intro to Asynchronous JavascriptIntro to Asynchronous Javascript
Intro to Asynchronous Javascript
 
Jquery
JqueryJquery
Jquery
 
Basics of JavaScript
Basics of JavaScriptBasics of JavaScript
Basics of JavaScript
 
Javascript event handler
Javascript event handlerJavascript event handler
Javascript event handler
 
JavaScript: Variables and Functions
JavaScript: Variables and FunctionsJavaScript: Variables and Functions
JavaScript: Variables and Functions
 
jQuery
jQueryjQuery
jQuery
 
JavaScript - Chapter 6 - Basic Functions
 JavaScript - Chapter 6 - Basic Functions JavaScript - Chapter 6 - Basic Functions
JavaScript - Chapter 6 - Basic Functions
 
Java script errors &amp; exceptions handling
Java script  errors &amp; exceptions handlingJava script  errors &amp; exceptions handling
Java script errors &amp; exceptions handling
 
JavaScript - Chapter 11 - Events
 JavaScript - Chapter 11 - Events  JavaScript - Chapter 11 - Events
JavaScript - Chapter 11 - Events
 
Form using html and java script validation
Form using html and java script validationForm using html and java script validation
Form using html and java script validation
 
스프링 시큐리티 구조 이해
스프링 시큐리티 구조 이해스프링 시큐리티 구조 이해
스프링 시큐리티 구조 이해
 
JavaScript - An Introduction
JavaScript - An IntroductionJavaScript - An Introduction
JavaScript - An Introduction
 
Javascript and DOM
Javascript and DOMJavascript and DOM
Javascript and DOM
 
JavaScript - Part-1
JavaScript - Part-1JavaScript - Part-1
JavaScript - Part-1
 

Viewers also liked

[ESC] Tài liệu về Tổ chức sự kiện
[ESC] Tài liệu về Tổ chức sự kiện [ESC] Tài liệu về Tổ chức sự kiện
[ESC] Tài liệu về Tổ chức sự kiện ESC Vietnam
 
Tìm đối tác kinh doanh truyền thông sự kiện
Tìm đối tác kinh doanh truyền thông sự kiệnTìm đối tác kinh doanh truyền thông sự kiện
Tìm đối tác kinh doanh truyền thông sự kiệnnexttopEVENT
 
Giới thiệu chung về tổ chức sự kiện VTR
Giới thiệu chung về tổ chức sự kiện VTRGiới thiệu chung về tổ chức sự kiện VTR
Giới thiệu chung về tổ chức sự kiện VTRVĩnh Thịnh Resort
 
Cask offline event #1 slide
Cask offline event #1 slideCask offline event #1 slide
Cask offline event #1 slideAn Nhien
 
Event Management - VNMG
Event Management - VNMGEvent Management - VNMG
Event Management - VNMGVy Lai
 
Bài Giảng Tổ Chức Sự Kiện
Bài Giảng Tổ Chức Sự KiệnBài Giảng Tổ Chức Sự Kiện
Bài Giảng Tổ Chức Sự KiệnHoàng Mai
 
J Street Productions Core Values #CultureCode
J Street Productions Core Values #CultureCodeJ Street Productions Core Values #CultureCode
J Street Productions Core Values #CultureCodeJ Street Productions
 
VIETNAMESE EVENT CHECKLIST & QUOTATION
VIETNAMESE EVENT CHECKLIST & QUOTATION VIETNAMESE EVENT CHECKLIST & QUOTATION
VIETNAMESE EVENT CHECKLIST & QUOTATION Son Huynh
 
Kiến thức cơ bản về tổ chức sự kiện
Kiến thức cơ bản về tổ chức sự kiệnKiến thức cơ bản về tổ chức sự kiện
Kiến thức cơ bản về tổ chức sự kiệnGiang Nguyen
 

Viewers also liked (10)

[ESC] Tài liệu về Tổ chức sự kiện
[ESC] Tài liệu về Tổ chức sự kiện [ESC] Tài liệu về Tổ chức sự kiện
[ESC] Tài liệu về Tổ chức sự kiện
 
Tìm đối tác kinh doanh truyền thông sự kiện
Tìm đối tác kinh doanh truyền thông sự kiệnTìm đối tác kinh doanh truyền thông sự kiện
Tìm đối tác kinh doanh truyền thông sự kiện
 
Giới thiệu chung về tổ chức sự kiện VTR
Giới thiệu chung về tổ chức sự kiện VTRGiới thiệu chung về tổ chức sự kiện VTR
Giới thiệu chung về tổ chức sự kiện VTR
 
Cask offline event #1 slide
Cask offline event #1 slideCask offline event #1 slide
Cask offline event #1 slide
 
Event Management - VNMG
Event Management - VNMGEvent Management - VNMG
Event Management - VNMG
 
Bài Giảng Tổ Chức Sự Kiện
Bài Giảng Tổ Chức Sự KiệnBài Giảng Tổ Chức Sự Kiện
Bài Giảng Tổ Chức Sự Kiện
 
J Street Productions Core Values #CultureCode
J Street Productions Core Values #CultureCodeJ Street Productions Core Values #CultureCode
J Street Productions Core Values #CultureCode
 
VIETNAMESE EVENT CHECKLIST & QUOTATION
VIETNAMESE EVENT CHECKLIST & QUOTATION VIETNAMESE EVENT CHECKLIST & QUOTATION
VIETNAMESE EVENT CHECKLIST & QUOTATION
 
Kiến thức cơ bản về tổ chức sự kiện
Kiến thức cơ bản về tổ chức sự kiệnKiến thức cơ bản về tổ chức sự kiện
Kiến thức cơ bản về tổ chức sự kiện
 
Event management
Event managementEvent management
Event management
 

Similar to JavaScript: Events Handling

The Fine Art of JavaScript Event Handling
The Fine Art of JavaScript Event HandlingThe Fine Art of JavaScript Event Handling
The Fine Art of JavaScript Event HandlingYorick Phoenix
 
JavaScript APIs - The Web is the Platform - MDN Hack Day, Sao Paulo
JavaScript APIs - The Web is the Platform - MDN Hack Day, Sao PauloJavaScript APIs - The Web is the Platform - MDN Hack Day, Sao Paulo
JavaScript APIs - The Web is the Platform - MDN Hack Day, Sao PauloRobert Nyman
 
jQuery 1.7 Events
jQuery 1.7 EventsjQuery 1.7 Events
jQuery 1.7 Eventsdmethvin
 
jQuery : Events are where it happens!
jQuery : Events are where it happens!jQuery : Events are where it happens!
jQuery : Events are where it happens!Wildan Maulana
 
JavaScript APIs - The Web is the Platform - MDN Hack Day, Santiago, Chile
JavaScript APIs - The Web is the Platform - MDN Hack Day, Santiago, ChileJavaScript APIs - The Web is the Platform - MDN Hack Day, Santiago, Chile
JavaScript APIs - The Web is the Platform - MDN Hack Day, Santiago, ChileRobert Nyman
 
JavaScript APIs - The Web is the Platform - MozCamp, Buenos Aires
JavaScript APIs - The Web is the Platform - MozCamp, Buenos AiresJavaScript APIs - The Web is the Platform - MozCamp, Buenos Aires
JavaScript APIs - The Web is the Platform - MozCamp, Buenos AiresRobert Nyman
 
JavaScript APIs - The Web is the Platform - MDN Hack Day, Montevideo
JavaScript APIs - The Web is the Platform - MDN Hack Day, MontevideoJavaScript APIs - The Web is the Platform - MDN Hack Day, Montevideo
JavaScript APIs - The Web is the Platform - MDN Hack Day, MontevideoRobert Nyman
 
HTML pour le web mobile, Firefox OS - Devfest Nantes - 2014-11-07
HTML pour le web mobile, Firefox OS - Devfest Nantes - 2014-11-07HTML pour le web mobile, Firefox OS - Devfest Nantes - 2014-11-07
HTML pour le web mobile, Firefox OS - Devfest Nantes - 2014-11-07Frédéric Harper
 
The Open Web and what it means
The Open Web and what it meansThe Open Web and what it means
The Open Web and what it meansRobert Nyman
 
Leaving Flatland: getting started with WebGL
Leaving Flatland: getting started with WebGLLeaving Flatland: getting started with WebGL
Leaving Flatland: getting started with WebGLgerbille
 
Building a js widget
Building a js widgetBuilding a js widget
Building a js widgetTudor Barbu
 
WebAPIs & WebRTC - Spotify/sthlm.js
WebAPIs & WebRTC - Spotify/sthlm.jsWebAPIs & WebRTC - Spotify/sthlm.js
WebAPIs & WebRTC - Spotify/sthlm.jsRobert Nyman
 
Secrets of JavaScript Libraries
Secrets of JavaScript LibrariesSecrets of JavaScript Libraries
Secrets of JavaScript Librariesjeresig
 
JavaScript APIs - The Web is the Platform - MDN Hack Day - Buenos Aires
JavaScript APIs - The Web is the Platform - MDN Hack Day - Buenos AiresJavaScript APIs - The Web is the Platform - MDN Hack Day - Buenos Aires
JavaScript APIs - The Web is the Platform - MDN Hack Day - Buenos AiresRobert Nyman
 

Similar to JavaScript: Events Handling (20)

Client Web
Client WebClient Web
Client Web
 
The Fine Art of JavaScript Event Handling
The Fine Art of JavaScript Event HandlingThe Fine Art of JavaScript Event Handling
The Fine Art of JavaScript Event Handling
 
Attribute actions
Attribute actionsAttribute actions
Attribute actions
 
Events.pdf
Events.pdfEvents.pdf
Events.pdf
 
JavaScript APIs - The Web is the Platform - MDN Hack Day, Sao Paulo
JavaScript APIs - The Web is the Platform - MDN Hack Day, Sao PauloJavaScript APIs - The Web is the Platform - MDN Hack Day, Sao Paulo
JavaScript APIs - The Web is the Platform - MDN Hack Day, Sao Paulo
 
Javascript Browser Events.pdf
Javascript Browser Events.pdfJavascript Browser Events.pdf
Javascript Browser Events.pdf
 
jQuery 1.7 Events
jQuery 1.7 EventsjQuery 1.7 Events
jQuery 1.7 Events
 
jQuery : Events are where it happens!
jQuery : Events are where it happens!jQuery : Events are where it happens!
jQuery : Events are where it happens!
 
JavaScript APIs - The Web is the Platform - MDN Hack Day, Santiago, Chile
JavaScript APIs - The Web is the Platform - MDN Hack Day, Santiago, ChileJavaScript APIs - The Web is the Platform - MDN Hack Day, Santiago, Chile
JavaScript APIs - The Web is the Platform - MDN Hack Day, Santiago, Chile
 
JavaScript APIs - The Web is the Platform - MozCamp, Buenos Aires
JavaScript APIs - The Web is the Platform - MozCamp, Buenos AiresJavaScript APIs - The Web is the Platform - MozCamp, Buenos Aires
JavaScript APIs - The Web is the Platform - MozCamp, Buenos Aires
 
JavaScript APIs - The Web is the Platform - MDN Hack Day, Montevideo
JavaScript APIs - The Web is the Platform - MDN Hack Day, MontevideoJavaScript APIs - The Web is the Platform - MDN Hack Day, Montevideo
JavaScript APIs - The Web is the Platform - MDN Hack Day, Montevideo
 
HTML pour le web mobile, Firefox OS - Devfest Nantes - 2014-11-07
HTML pour le web mobile, Firefox OS - Devfest Nantes - 2014-11-07HTML pour le web mobile, Firefox OS - Devfest Nantes - 2014-11-07
HTML pour le web mobile, Firefox OS - Devfest Nantes - 2014-11-07
 
The Open Web and what it means
The Open Web and what it meansThe Open Web and what it means
The Open Web and what it means
 
Leaving Flatland: getting started with WebGL
Leaving Flatland: getting started with WebGLLeaving Flatland: getting started with WebGL
Leaving Flatland: getting started with WebGL
 
DOM Events
DOM EventsDOM Events
DOM Events
 
Events
EventsEvents
Events
 
Building a js widget
Building a js widgetBuilding a js widget
Building a js widget
 
WebAPIs & WebRTC - Spotify/sthlm.js
WebAPIs & WebRTC - Spotify/sthlm.jsWebAPIs & WebRTC - Spotify/sthlm.js
WebAPIs & WebRTC - Spotify/sthlm.js
 
Secrets of JavaScript Libraries
Secrets of JavaScript LibrariesSecrets of JavaScript Libraries
Secrets of JavaScript Libraries
 
JavaScript APIs - The Web is the Platform - MDN Hack Day - Buenos Aires
JavaScript APIs - The Web is the Platform - MDN Hack Day - Buenos AiresJavaScript APIs - The Web is the Platform - MDN Hack Day - Buenos Aires
JavaScript APIs - The Web is the Platform - MDN Hack Day - Buenos Aires
 

Recently uploaded

Font Performance - NYC WebPerf Meetup April '24
Font Performance - NYC WebPerf Meetup April '24Font Performance - NYC WebPerf Meetup April '24
Font Performance - NYC WebPerf Meetup April '24Paul Calvano
 
Top 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptxTop 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptxDyna Gilbert
 
Q4-1-Illustrating-Hypothesis-Testing.pptx
Q4-1-Illustrating-Hypothesis-Testing.pptxQ4-1-Illustrating-Hypothesis-Testing.pptx
Q4-1-Illustrating-Hypothesis-Testing.pptxeditsforyah
 
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书rnrncn29
 
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作ys8omjxb
 
NSX-T and Service Interfaces presentation
NSX-T and Service Interfaces presentationNSX-T and Service Interfaces presentation
NSX-T and Service Interfaces presentationMarko4394
 
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170Sonam Pathan
 
Contact Rya Baby for Call Girls New Delhi
Contact Rya Baby for Call Girls New DelhiContact Rya Baby for Call Girls New Delhi
Contact Rya Baby for Call Girls New Delhimiss dipika
 
SCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is prediSCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is predieusebiomeyer
 
Call Girls Near The Suryaa Hotel New Delhi 9873777170
Call Girls Near The Suryaa Hotel New Delhi 9873777170Call Girls Near The Suryaa Hotel New Delhi 9873777170
Call Girls Near The Suryaa Hotel New Delhi 9873777170Sonam Pathan
 
Film cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasaFilm cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasa494f574xmv
 
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书zdzoqco
 
PHP-based rendering of TYPO3 Documentation
PHP-based rendering of TYPO3 DocumentationPHP-based rendering of TYPO3 Documentation
PHP-based rendering of TYPO3 DocumentationLinaWolf1
 
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一z xss
 
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书rnrncn29
 

Recently uploaded (17)

Font Performance - NYC WebPerf Meetup April '24
Font Performance - NYC WebPerf Meetup April '24Font Performance - NYC WebPerf Meetup April '24
Font Performance - NYC WebPerf Meetup April '24
 
Top 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptxTop 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptx
 
young call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Service
young call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Service
young call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Service
 
Q4-1-Illustrating-Hypothesis-Testing.pptx
Q4-1-Illustrating-Hypothesis-Testing.pptxQ4-1-Illustrating-Hypothesis-Testing.pptx
Q4-1-Illustrating-Hypothesis-Testing.pptx
 
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
 
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
 
NSX-T and Service Interfaces presentation
NSX-T and Service Interfaces presentationNSX-T and Service Interfaces presentation
NSX-T and Service Interfaces presentation
 
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
 
Contact Rya Baby for Call Girls New Delhi
Contact Rya Baby for Call Girls New DelhiContact Rya Baby for Call Girls New Delhi
Contact Rya Baby for Call Girls New Delhi
 
SCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is prediSCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is predi
 
Call Girls Near The Suryaa Hotel New Delhi 9873777170
Call Girls Near The Suryaa Hotel New Delhi 9873777170Call Girls Near The Suryaa Hotel New Delhi 9873777170
Call Girls Near The Suryaa Hotel New Delhi 9873777170
 
Film cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasaFilm cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasa
 
Hot Sexy call girls in Rk Puram 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in  Rk Puram 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in  Rk Puram 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Rk Puram 🔝 9953056974 🔝 Delhi escort Service
 
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
 
PHP-based rendering of TYPO3 Documentation
PHP-based rendering of TYPO3 DocumentationPHP-based rendering of TYPO3 Documentation
PHP-based rendering of TYPO3 Documentation
 
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
 
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
 

JavaScript: Events Handling

  • 1. JavaScript: Events and Events Handling Yuriy Bezgachnyuk August, 2014
  • 2. Special Thanks to John Resig
  • 3. Agenda ▪Events – What is event – Phases of event – How to handle events – Event Object – Keyboard and mouse events ▪Exception handling
  • 4. Events ▪Event – an action that is fired (initiated) within a web page. ▪JavaScript is Single Thread ▪JavaScript uses asynchronous callback
  • 5. Phases of Event ▪Phase #1 – Capturing ▪Phase #2 – Bubbling
  • 6. Defining Event Handler ▪Old way window.onload = function() {}; ▪New way (add event) window.addEventListener(”load”,func,false) window.attachEvent(”onload”,func); // IE < 9 ▪We can define event handler only for objects!!!
  • 7. The Event Object ▪Contains contextual information about the current event ▪An object that’s provided, or is available, inside of every event handler function ▪W3C Standard Browser: e ▪Internet Explorer: window.event
  • 8. Cancel Bubbling ▪Since you know how event capturing/bubbling works, let’s explore how you can take control it. ▪W3C – e.stopPropagation() ▪IE – window.event.cancelBubble ▪Live Example (Thanks for J. Resig )
  • 10. Cancel Bubbling (Code + Live) function stopBuuble(e) { if (e && e.stopPropagation) { e.stopPropagation(); } else { window.event.cancelBubble = true; } } var all = document.getElementsByTagName("*"); for (var i = 0;i < all.length;i++) { all[i].onmouseover = function(e) { this.style.border = "1px solid red"; stopBuuble(e); }; all[i].onmouseout = function(e) { this.style.border = "0px"; stopBuuble(e); }; }
  • 11. Overriding Browser Default Event ▪For most events that take place, the browser has some default action that will always occur. – For example, clicking an <a> element will take you to its associated web page; this is a default action in the browser. This action will always occur after both the capturing and the bubbling event phases
  • 12. Overriding {code: true, live:true} function stopDefault(e) { if (e && e.preventDefault) { e.preventDefault(); } else { window.event.returnValue = false; } } var iframe = document.getElementById("iframe"); var a = document.getElementsByTagName("a"); for (var i = 0;i < a.length;i++) { a[i].onclick = function(e) { iframe.src = this.href; return stopDefault(e); }; }
  • 13. Keyboard and Mouse Events ▪Mouse Events – onMouseDown – onMouseMove – onMouseOut – onMouseOver – onMouseUp – onClick – onDblClick – onDragDrop ▪Keyboard Events – onKeyDown – onKeyPress – onKeyUp
  • 14. Practice: Handling Mouse events ▪Task: <div> container must change bg-color after some mouse event – hover => yellow; – click => red; – dblclick =>blue; – out =>white;
  • 15. Code <body> <div id="container"> </div> <script type="text/javascript"> var div_c = document.getElementById("container"); div_c.addEventListener("mouseover", a, false); div_c.addEventListener("mouseout", b, false); div_c.addEventListener("click", c, false); div_c.addEventListener("dblclick", d, false); </script> </body> ... function a() { div_c.style.backgroundColor = "yellow"; }
  • 16. Keyboard Events Handling ▪Let’s investigate little part of code <script type="text/javascript"> window.addEventListener("keydown", handleEvent, false); window.addEventListener("keypress", handleEvent, false); window.addEventListener("keyup", handleEvent, false); </script> <script type="text/javascript"> function handleEvent(e) { var e = e || window.event; console.log(e); } </script>
  • 17. And so what we have…? ▪After investigation previous slide we can see next features of KB events: – keydown  keypress  keyup (sequence of KB events!!!) – Some KB events have value (not 0) of property charCode (keypress event only). – keydown and keyup events generate scan-code only (keyCode property) which always similar and don’t depends on KB layout!!!
  • 18. References and sources 1. John Resig Pro JavaScript Techniques 2. David Flenagan JavaScript 3. Christian Wenz JavaScript Phrasebook 4. https://developer.mozilla.org/