SlideShare a Scribd company logo
JavaScript	
  Browser	
  Object	
  Model	
  
(BOM)	
  
Jussi	
  Pohjolainen	
  
Tampere	
  University	
  of	
  Applied	
  Sciences	
  
Objects?	
  
•  NaDve	
  (Core	
  Javascript)	
  
– ECMAScript	
  standard:	
  Array,	
  Date..	
  
•  Host 	
  	
  
– The	
  host	
  environment,	
  for	
  example	
  browser:	
  
BOM,	
  DOM	
  objects	
  
•  JavaScript	
  =	
  ECMAScript	
  +	
  BOM	
  +	
  DOM	
  
	
  
	
  
BOM	
  vs	
  DOM?	
  
•  BOM	
  
–  Browser	
  Object	
  Model	
  
–  Access	
  and	
  manipulaDon	
  of	
  the	
  browser	
  window	
  
–  No	
  standard,	
  in	
  theory	
  every	
  browser	
  can	
  have	
  it's	
  own	
  
implementaDon	
  of	
  BOM	
  
–  In	
  pracDce	
  almost	
  all	
  modern	
  browsers	
  share	
  the	
  same	
  objects	
  
•  DOM	
  
–  Document	
  Object	
  Model	
  
–  Different	
  levels	
  (1,2,3)	
  
–  Manipulate	
  the	
  html	
  document	
  
–  W3C	
  RecommendaDon	
  (not	
  JS	
  specific!)	
  
•  hYp://www.w3.org/DOM/	
  
Some	
  BOM	
  Objects	
  
•  window	
  –	
  browser	
  window	
  
– navigator	
  –	
  informaDon	
  about	
  the	
  browser	
  
– history	
  –	
  going	
  back	
  and	
  forward	
  in	
  browser	
  
history	
  
– screen	
  –	
  informaDon	
  about	
  the	
  user	
  screen	
  
– location	
  –	
  informaDon	
  about	
  the	
  url	
  
– document	
  (this	
  is	
  DOM!,	
  we	
  will	
  look	
  at	
  this	
  later)	
  
	
  
window
•  DocumentaDon	
  
–  https://developer.mozilla.org/en-US/docs/Web/
API/Window
Example	
  Usage	
  
window.setTimeout('alert("I will appear
after 3 seconds.")', 3000);
window.setInterval('alert("I will
reappear every 3 seconds.")', 3000);
window.screen
•  DocumentaDon	
  
–  https://developer.mozilla.org/en-US/docs/Web/
API/window.screen	
  
window.navigator
•  navigator	
  tells	
  informaDon	
  about	
  your	
  browser	
  
•  DocumentaDon	
  
–  hYps://developer.mozilla.org/en-­‐US/docs/Web/API/
Navigator	
  
•  Client-­‐sniffing	
  
var browser = navigator.appName;
var b_version = navigator.appVersion;
var version = parseFloat(b_version);
document.write("Browser name: "+ browser);
document.write("<br />");
document.write("Browser version: "+ version);
history	
  and	
  locaDon	
  
•  history	
  
– hYps://developer.mozilla.org/en-­‐US/docs/Web/
API/window.history	
  
•  locaDon	
  
– hYps://developer.mozilla.org/en-­‐US/docs/Web/
API/window.locaDon	
  
	
  
Accessing	
  Forms	
  in	
  DOM	
  0	
  
document.forms[’myform'].elements['address']
document.forms['myform'].elements[0]
document.forms[0].elements['address’]
document.forms[0].elements[0]
ABOUT	
  JAVASCRIPT	
  EVENTS	
  
Intro	
  to	
  Events	
  
•  When	
  adding	
  interacDvity	
  to	
  your	
  apps,	
  you	
  use	
  
events	
  
–  how	
  to	
  act	
  when	
  user	
  reacts	
  to	
  something	
  
•  Different	
  models	
  
–  Tradi:onal	
  model:	
  aYach	
  an	
  event	
  handler	
  to	
  certain	
  
html	
  elements,	
  mostly	
  links	
  and	
  form	
  fields.	
  IE	
  and	
  
others	
  conforms	
  to	
  Netscape	
  2	
  model	
  
–  Modern	
  event	
  model:	
  totally	
  different	
  models	
  in	
  
netscape	
  and	
  microsoc	
  ie	
  
–  W3C	
  DOM	
  Event	
  specifica:on:	
  effort	
  to	
  bring	
  
constant	
  event	
  handling	
  to	
  all	
  browsers	
  
TradiDonal	
  Model	
  
•  Works	
  fine!	
  
•  Most	
  HTML	
  elements	
  have	
  properDes	
  like	
  
onclick,	
  onmouseover,	
  onkeypress, onload,
onsubmit
–  Which	
  elements	
  hold	
  which	
  properDes?	
  Depends	
  on	
  
the	
  browser…	
  
•  How?	
  
–  <a href="site.html" onclick="doSomething()">
•  See	
  events	
  and	
  compability	
  list	
  
–  http://www.quirksmode.org/dom/events/
index.html
Canceling	
  	
  
•  You	
  may	
  cancel	
  some	
  events:	
  
– <a href=http://www.tamk.fi/
onclick="alert('message'); return
false;">
•  Example	
  
– <form name="myform" action=""
onsubmit="return validate();">
Example	
  of	
  TradiDonal	
  Model	
  	
  
<form name="myform" method="post" onsubmit="return count()">
Height (m):<br/>
<input type="text" name="height"/><br/>
Weight (kg):<br/>
<input type="text" name="weight"/><br/>
<input type="submit" value="BMI"/><br/>
BMI<br/>
<input type="text" name="result"/>
</form>
<script type="text/javascript">
//<![CDATA[
function count()
{
// Uses DOM LEVEL 0
var height = document.myform.height.value;
var weight = document.myform.weight.value;
document.myform.result.value = (weight / (height*height));
return false;
}
//]]>
</script>
Advanced	
  Event	
  Handling	
  
•  W3C	
  and	
  Microsoc	
  have	
  their	
  own	
  event	
  
registraDon	
  model	
  
– Since	
  IE9	
  MS	
  decided	
  to	
  support	
  also	
  W3C	
  model!	
  
•  W3C	
  model	
  is	
  supported	
  in	
  WebKit/Blink	
  
(chrome	
  +	
  safari	
  +	
  opera),	
  firefox	
  (gecko)	
  and	
  
IE9	
  -­‐>	
  
•  In	
  W3C	
  event	
  model,	
  it's	
  possible	
  to	
  register	
  
as	
  many	
  event	
  handlers	
  as	
  you	
  like	
  for	
  the	
  
same	
  event	
  on	
  one	
  element.	
  
<a href="http://www.tamk.fi" id="mylink">Click Me!</a>
<script>
function showAlert1()
{
alert("click 1!");
}
function showAlert2()
{
alert("click 2!");
}
var link = window.document.getElementById("mylink");
link.addEventListener('click', showAlert1, false);
link.addEventListener('click', showAlert2, false);
</script>
true	
  or	
  false?	
  
•  The	
  boolean	
  value	
  (true,	
  false)	
  is	
  related	
  to	
  event	
  
handling	
  order	
  
•  If	
  an	
  element	
  and	
  one	
  of	
  its	
  ancestors	
  have	
  an	
  
event	
  handler	
  for	
  the	
  same	
  event,	
  which	
  one	
  
should	
  fire	
  first?	
  
•  See	
  
–  hYp://www.quirksmode.org/js/events_order.html	
  
•  See	
  also	
  good	
  summary:	
  
–  hYp://www.w3.org/wiki/
Handling_events_with_JavaScript	
  

More Related Content

What's hot

Java Script
Java ScriptJava Script
Java Script
husbancom
 
HTML CSS & Javascript
HTML CSS & JavascriptHTML CSS & Javascript
HTML CSS & Javascript
David Lindkvist
 
React JS - A quick introduction tutorial
React JS - A quick introduction tutorialReact JS - A quick introduction tutorial
React JS - A quick introduction tutorial
Mohammed Fazuluddin
 
JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript Programming
Sehwan Noh
 
[Final] ReactJS presentation
[Final] ReactJS presentation[Final] ReactJS presentation
[Final] ReactJS presentation洪 鹏发
 
jQuery for beginners
jQuery for beginnersjQuery for beginners
jQuery for beginners
Arulmurugan Rajaraman
 
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...
Edureka!
 
Java script
Java scriptJava script
Java script
Jay Patel
 
Javascript
JavascriptJavascript
Javascript
Nagarajan
 
JavaScript: Variables and Functions
JavaScript: Variables and FunctionsJavaScript: Variables and Functions
JavaScript: Variables and FunctionsJussi Pohjolainen
 
A Brief Introduction to React.js
A Brief Introduction to React.jsA Brief Introduction to React.js
A Brief Introduction to React.js
Doug Neiner
 
Workshop 21: React Router
Workshop 21: React RouterWorkshop 21: React Router
Workshop 21: React Router
Visual Engineering
 
Intro to React
Intro to ReactIntro to React
Intro to React
Justin Reock
 
javaScript.ppt
javaScript.pptjavaScript.ppt
javaScript.ppt
sentayehu
 
Php.ppt
Php.pptPhp.ppt
Php.ppt
Nidhi mishra
 
Javascript
JavascriptJavascript
Javascript
mussawir20
 
Bootstrap 5 ppt
Bootstrap 5 pptBootstrap 5 ppt
Bootstrap 5 ppt
Mallikarjuna G D
 
Javascript 101
Javascript 101Javascript 101
Javascript 101
Shlomi Komemi
 
Javascript
JavascriptJavascript
Javascript
Manav Prasad
 
What Is Virtual DOM In React JS.pptx
What Is Virtual DOM In React JS.pptxWhat Is Virtual DOM In React JS.pptx
What Is Virtual DOM In React JS.pptx
Akrati Rawat
 

What's hot (20)

Java Script
Java ScriptJava Script
Java Script
 
HTML CSS & Javascript
HTML CSS & JavascriptHTML CSS & Javascript
HTML CSS & Javascript
 
React JS - A quick introduction tutorial
React JS - A quick introduction tutorialReact JS - A quick introduction tutorial
React JS - A quick introduction tutorial
 
JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript Programming
 
[Final] ReactJS presentation
[Final] ReactJS presentation[Final] ReactJS presentation
[Final] ReactJS presentation
 
jQuery for beginners
jQuery for beginnersjQuery for beginners
jQuery for beginners
 
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...
 
Java script
Java scriptJava script
Java script
 
Javascript
JavascriptJavascript
Javascript
 
JavaScript: Variables and Functions
JavaScript: Variables and FunctionsJavaScript: Variables and Functions
JavaScript: Variables and Functions
 
A Brief Introduction to React.js
A Brief Introduction to React.jsA Brief Introduction to React.js
A Brief Introduction to React.js
 
Workshop 21: React Router
Workshop 21: React RouterWorkshop 21: React Router
Workshop 21: React Router
 
Intro to React
Intro to ReactIntro to React
Intro to React
 
javaScript.ppt
javaScript.pptjavaScript.ppt
javaScript.ppt
 
Php.ppt
Php.pptPhp.ppt
Php.ppt
 
Javascript
JavascriptJavascript
Javascript
 
Bootstrap 5 ppt
Bootstrap 5 pptBootstrap 5 ppt
Bootstrap 5 ppt
 
Javascript 101
Javascript 101Javascript 101
Javascript 101
 
Javascript
JavascriptJavascript
Javascript
 
What Is Virtual DOM In React JS.pptx
What Is Virtual DOM In React JS.pptxWhat Is Virtual DOM In React JS.pptx
What Is Virtual DOM In React JS.pptx
 

Viewers also liked

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
Yorick Phoenix
 
JavaScript event handling assignment
JavaScript  event handling assignment JavaScript  event handling assignment
JavaScript event handling assignment
Soham Sengupta
 
Browser Object Model
Browser Object ModelBrowser Object Model
Browser Object Model
jay li
 
Browser Object Model and Animations in qooxdoo
Browser Object Model and Animations in qooxdooBrowser Object Model and Animations in qooxdoo
Browser Object Model and Animations in qooxdoo
Sebastian Werner
 
JavaScript From Scratch: Events
JavaScript From Scratch: EventsJavaScript From Scratch: Events
JavaScript From Scratch: Events
Michael Girouard
 
Yahoo presentation: JavaScript Events
Yahoo presentation: JavaScript EventsYahoo presentation: JavaScript Events
Yahoo presentation: JavaScript Events
Peter-Paul Koch
 
Javascript and DOM
Javascript and DOMJavascript and DOM
Javascript and DOM
Brian Moschel
 
System model
System modelSystem model
System model
soniaamim
 
Introduction to the DOM
Introduction to the DOMIntroduction to the DOM
Introduction to the DOM
tharaa abu ashour
 
JavaScript: Events Handling
JavaScript: Events HandlingJavaScript: Events Handling
JavaScript: Events Handling
Yuriy Bezgachnyuk
 
JavaScript - An Introduction
JavaScript - An IntroductionJavaScript - An Introduction
JavaScript - An Introduction
Manvendra Singh
 
jQuery Essentials
jQuery EssentialsjQuery Essentials
jQuery Essentials
Marc Grabanski
 

Viewers also liked (13)

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
 
JavaScript event handling assignment
JavaScript  event handling assignment JavaScript  event handling assignment
JavaScript event handling assignment
 
Browser Object Model
Browser Object ModelBrowser Object Model
Browser Object Model
 
Browser Object Model and Animations in qooxdoo
Browser Object Model and Animations in qooxdooBrowser Object Model and Animations in qooxdoo
Browser Object Model and Animations in qooxdoo
 
JavaScript From Scratch: Events
JavaScript From Scratch: EventsJavaScript From Scratch: Events
JavaScript From Scratch: Events
 
Yahoo presentation: JavaScript Events
Yahoo presentation: JavaScript EventsYahoo presentation: JavaScript Events
Yahoo presentation: JavaScript Events
 
Javascript and DOM
Javascript and DOMJavascript and DOM
Javascript and DOM
 
System model
System modelSystem model
System model
 
Introduction to the DOM
Introduction to the DOMIntroduction to the DOM
Introduction to the DOM
 
JavaScript: Events Handling
JavaScript: Events HandlingJavaScript: Events Handling
JavaScript: Events Handling
 
JavaScript - An Introduction
JavaScript - An IntroductionJavaScript - An Introduction
JavaScript - An Introduction
 
Web Servers (ppt)
Web Servers (ppt)Web Servers (ppt)
Web Servers (ppt)
 
jQuery Essentials
jQuery EssentialsjQuery Essentials
jQuery Essentials
 

Similar to JavaScript and BOM events

Speeding up mobile web apps
Speeding up mobile web appsSpeeding up mobile web apps
Speeding up mobile web apps
Ivano Malavolta
 
Fast Cordova applications
Fast Cordova applicationsFast Cordova applications
Fast Cordova applications
Ivano Malavolta
 
Fast mobile web apps
Fast mobile web appsFast mobile web apps
Fast mobile web apps
Ivano Malavolta
 
Week 05 Web, App and Javascript_Brandon, S.H. Wu
Week 05 Web, App and Javascript_Brandon, S.H. WuWeek 05 Web, App and Javascript_Brandon, S.H. Wu
Week 05 Web, App and Javascript_Brandon, S.H. Wu
AppUniverz Org
 
JavaScript
JavaScriptJavaScript
JavaScript
Vidyut Singhania
 
JavaScript DOM & event
JavaScript DOM & eventJavaScript DOM & event
JavaScript DOM & eventBorey Lim
 
Intro to mobile web application development
Intro to mobile web application developmentIntro to mobile web application development
Intro to mobile web application development
zonathen
 
Learn javascript easy steps
Learn javascript easy stepsLearn javascript easy steps
Learn javascript easy steps
prince Loffar
 
Modern Web Technologies
Modern Web TechnologiesModern Web Technologies
Modern Web Technologies
Perttu Myry
 
Javascript Update May 2013
Javascript Update May 2013Javascript Update May 2013
Javascript Update May 2013
Ramesh Nair
 
Basic web security model
Basic web security modelBasic web security model
Basic web security model
G Prachi
 
Advanced guide to develop ajax applications using dojo
Advanced guide to develop ajax applications using dojoAdvanced guide to develop ajax applications using dojo
Advanced guide to develop ajax applications using dojo
Fu Cheng
 
jQuery - Chapter 1 - Introduction
 jQuery - Chapter 1 - Introduction jQuery - Chapter 1 - Introduction
jQuery - Chapter 1 - Introduction
WebStackAcademy
 
Javascript inside Browser (DOM)
Javascript inside Browser (DOM)Javascript inside Browser (DOM)
Javascript inside Browser (DOM)
Vlad Mysla
 
Intro JavaScript
Intro JavaScriptIntro JavaScript
Intro JavaScript
koppenolski
 
Mobile and IBM Worklight Best Practices
Mobile and IBM Worklight Best PracticesMobile and IBM Worklight Best Practices
Mobile and IBM Worklight Best PracticesAndrew Ferrier
 

Similar to JavaScript and BOM events (20)

Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
Speeding up mobile web apps
Speeding up mobile web appsSpeeding up mobile web apps
Speeding up mobile web apps
 
Fast Cordova applications
Fast Cordova applicationsFast Cordova applications
Fast Cordova applications
 
Intro to JavaScript
Intro to JavaScriptIntro to JavaScript
Intro to JavaScript
 
Fast mobile web apps
Fast mobile web appsFast mobile web apps
Fast mobile web apps
 
Cos 432 web_security
Cos 432 web_securityCos 432 web_security
Cos 432 web_security
 
Week 05 Web, App and Javascript_Brandon, S.H. Wu
Week 05 Web, App and Javascript_Brandon, S.H. WuWeek 05 Web, App and Javascript_Brandon, S.H. Wu
Week 05 Web, App and Javascript_Brandon, S.H. Wu
 
JavaScript
JavaScriptJavaScript
JavaScript
 
JavaScript DOM & event
JavaScript DOM & eventJavaScript DOM & event
JavaScript DOM & event
 
Intro to mobile web application development
Intro to mobile web application developmentIntro to mobile web application development
Intro to mobile web application development
 
Learn javascript easy steps
Learn javascript easy stepsLearn javascript easy steps
Learn javascript easy steps
 
Modern Web Technologies
Modern Web TechnologiesModern Web Technologies
Modern Web Technologies
 
Javascript Update May 2013
Javascript Update May 2013Javascript Update May 2013
Javascript Update May 2013
 
Basic web security model
Basic web security modelBasic web security model
Basic web security model
 
Advanced guide to develop ajax applications using dojo
Advanced guide to develop ajax applications using dojoAdvanced guide to develop ajax applications using dojo
Advanced guide to develop ajax applications using dojo
 
DOM Structure
DOM StructureDOM Structure
DOM Structure
 
jQuery - Chapter 1 - Introduction
 jQuery - Chapter 1 - Introduction jQuery - Chapter 1 - Introduction
jQuery - Chapter 1 - Introduction
 
Javascript inside Browser (DOM)
Javascript inside Browser (DOM)Javascript inside Browser (DOM)
Javascript inside Browser (DOM)
 
Intro JavaScript
Intro JavaScriptIntro JavaScript
Intro JavaScript
 
Mobile and IBM Worklight Best Practices
Mobile and IBM Worklight Best PracticesMobile and IBM Worklight Best Practices
Mobile and IBM Worklight Best Practices
 

More from Jussi Pohjolainen

Moved to Speakerdeck
Moved to SpeakerdeckMoved to Speakerdeck
Moved to Speakerdeck
Jussi Pohjolainen
 
Java Web Services
Java Web ServicesJava Web Services
Java Web Services
Jussi Pohjolainen
 
Box2D and libGDX
Box2D and libGDXBox2D and libGDX
Box2D and libGDX
Jussi Pohjolainen
 
libGDX: Screens, Fonts and Preferences
libGDX: Screens, Fonts and PreferenceslibGDX: Screens, Fonts and Preferences
libGDX: Screens, Fonts and Preferences
Jussi Pohjolainen
 
libGDX: Tiled Maps
libGDX: Tiled MapslibGDX: Tiled Maps
libGDX: Tiled Maps
Jussi Pohjolainen
 
libGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame AnimationlibGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame Animation
Jussi Pohjolainen
 
Intro to Building Android Games using libGDX
Intro to Building Android Games using libGDXIntro to Building Android Games using libGDX
Intro to Building Android Games using libGDX
Jussi Pohjolainen
 
Advanced JavaScript Development
Advanced JavaScript DevelopmentAdvanced JavaScript Development
Advanced JavaScript DevelopmentJussi Pohjolainen
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
Jussi Pohjolainen
 
libGDX: Scene2D
libGDX: Scene2DlibGDX: Scene2D
libGDX: Scene2D
Jussi Pohjolainen
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame AnimationJussi Pohjolainen
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame Animation
Jussi Pohjolainen
 
libGDX: User Input
libGDX: User InputlibGDX: User Input
libGDX: User Input
Jussi Pohjolainen
 
Implementing a Simple Game using libGDX
Implementing a Simple Game using libGDXImplementing a Simple Game using libGDX
Implementing a Simple Game using libGDX
Jussi Pohjolainen
 
Building Android games using LibGDX
Building Android games using LibGDXBuilding Android games using LibGDX
Building Android games using LibGDX
Jussi Pohjolainen
 
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and GesturesCreating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and GesturesJussi Pohjolainen
 
Creating Games for Asha - platform
Creating Games for Asha - platformCreating Games for Asha - platform
Creating Games for Asha - platformJussi Pohjolainen
 
Intro to Java ME and Asha Platform
Intro to Java ME and Asha PlatformIntro to Java ME and Asha Platform
Intro to Java ME and Asha PlatformJussi Pohjolainen
 

More from Jussi Pohjolainen (20)

Moved to Speakerdeck
Moved to SpeakerdeckMoved to Speakerdeck
Moved to Speakerdeck
 
Java Web Services
Java Web ServicesJava Web Services
Java Web Services
 
Box2D and libGDX
Box2D and libGDXBox2D and libGDX
Box2D and libGDX
 
libGDX: Screens, Fonts and Preferences
libGDX: Screens, Fonts and PreferenceslibGDX: Screens, Fonts and Preferences
libGDX: Screens, Fonts and Preferences
 
libGDX: Tiled Maps
libGDX: Tiled MapslibGDX: Tiled Maps
libGDX: Tiled Maps
 
libGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame AnimationlibGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame Animation
 
Intro to Building Android Games using libGDX
Intro to Building Android Games using libGDXIntro to Building Android Games using libGDX
Intro to Building Android Games using libGDX
 
Advanced JavaScript Development
Advanced JavaScript DevelopmentAdvanced JavaScript Development
Advanced JavaScript Development
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
 
libGDX: Scene2D
libGDX: Scene2DlibGDX: Scene2D
libGDX: Scene2D
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame Animation
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame Animation
 
libGDX: User Input
libGDX: User InputlibGDX: User Input
libGDX: User Input
 
Implementing a Simple Game using libGDX
Implementing a Simple Game using libGDXImplementing a Simple Game using libGDX
Implementing a Simple Game using libGDX
 
Building Android games using LibGDX
Building Android games using LibGDXBuilding Android games using LibGDX
Building Android games using LibGDX
 
Android Threading
Android ThreadingAndroid Threading
Android Threading
 
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and GesturesCreating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
 
Creating Games for Asha - platform
Creating Games for Asha - platformCreating Games for Asha - platform
Creating Games for Asha - platform
 
Intro to Asha UI
Intro to Asha UIIntro to Asha UI
Intro to Asha UI
 
Intro to Java ME and Asha Platform
Intro to Java ME and Asha PlatformIntro to Java ME and Asha Platform
Intro to Java ME and Asha Platform
 

Recently uploaded

Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 

Recently uploaded (20)

Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 

JavaScript and BOM events

  • 1. JavaScript  Browser  Object  Model   (BOM)   Jussi  Pohjolainen   Tampere  University  of  Applied  Sciences  
  • 2. Objects?   •  NaDve  (Core  Javascript)   – ECMAScript  standard:  Array,  Date..   •  Host     – The  host  environment,  for  example  browser:   BOM,  DOM  objects   •  JavaScript  =  ECMAScript  +  BOM  +  DOM      
  • 3. BOM  vs  DOM?   •  BOM   –  Browser  Object  Model   –  Access  and  manipulaDon  of  the  browser  window   –  No  standard,  in  theory  every  browser  can  have  it's  own   implementaDon  of  BOM   –  In  pracDce  almost  all  modern  browsers  share  the  same  objects   •  DOM   –  Document  Object  Model   –  Different  levels  (1,2,3)   –  Manipulate  the  html  document   –  W3C  RecommendaDon  (not  JS  specific!)   •  hYp://www.w3.org/DOM/  
  • 4. Some  BOM  Objects   •  window  –  browser  window   – navigator  –  informaDon  about  the  browser   – history  –  going  back  and  forward  in  browser   history   – screen  –  informaDon  about  the  user  screen   – location  –  informaDon  about  the  url   – document  (this  is  DOM!,  we  will  look  at  this  later)    
  • 5. window •  DocumentaDon   –  https://developer.mozilla.org/en-US/docs/Web/ API/Window
  • 6. Example  Usage   window.setTimeout('alert("I will appear after 3 seconds.")', 3000); window.setInterval('alert("I will reappear every 3 seconds.")', 3000);
  • 7. window.screen •  DocumentaDon   –  https://developer.mozilla.org/en-US/docs/Web/ API/window.screen  
  • 8. window.navigator •  navigator  tells  informaDon  about  your  browser   •  DocumentaDon   –  hYps://developer.mozilla.org/en-­‐US/docs/Web/API/ Navigator   •  Client-­‐sniffing   var browser = navigator.appName; var b_version = navigator.appVersion; var version = parseFloat(b_version); document.write("Browser name: "+ browser); document.write("<br />"); document.write("Browser version: "+ version);
  • 9. history  and  locaDon   •  history   – hYps://developer.mozilla.org/en-­‐US/docs/Web/ API/window.history   •  locaDon   – hYps://developer.mozilla.org/en-­‐US/docs/Web/ API/window.locaDon    
  • 10. Accessing  Forms  in  DOM  0   document.forms[’myform'].elements['address'] document.forms['myform'].elements[0] document.forms[0].elements['address’] document.forms[0].elements[0]
  • 12. Intro  to  Events   •  When  adding  interacDvity  to  your  apps,  you  use   events   –  how  to  act  when  user  reacts  to  something   •  Different  models   –  Tradi:onal  model:  aYach  an  event  handler  to  certain   html  elements,  mostly  links  and  form  fields.  IE  and   others  conforms  to  Netscape  2  model   –  Modern  event  model:  totally  different  models  in   netscape  and  microsoc  ie   –  W3C  DOM  Event  specifica:on:  effort  to  bring   constant  event  handling  to  all  browsers  
  • 13. TradiDonal  Model   •  Works  fine!   •  Most  HTML  elements  have  properDes  like   onclick,  onmouseover,  onkeypress, onload, onsubmit –  Which  elements  hold  which  properDes?  Depends  on   the  browser…   •  How?   –  <a href="site.html" onclick="doSomething()"> •  See  events  and  compability  list   –  http://www.quirksmode.org/dom/events/ index.html
  • 14. Canceling     •  You  may  cancel  some  events:   – <a href=http://www.tamk.fi/ onclick="alert('message'); return false;"> •  Example   – <form name="myform" action="" onsubmit="return validate();">
  • 15. Example  of  TradiDonal  Model     <form name="myform" method="post" onsubmit="return count()"> Height (m):<br/> <input type="text" name="height"/><br/> Weight (kg):<br/> <input type="text" name="weight"/><br/> <input type="submit" value="BMI"/><br/> BMI<br/> <input type="text" name="result"/> </form>
  • 16. <script type="text/javascript"> //<![CDATA[ function count() { // Uses DOM LEVEL 0 var height = document.myform.height.value; var weight = document.myform.weight.value; document.myform.result.value = (weight / (height*height)); return false; } //]]> </script>
  • 17. Advanced  Event  Handling   •  W3C  and  Microsoc  have  their  own  event   registraDon  model   – Since  IE9  MS  decided  to  support  also  W3C  model!   •  W3C  model  is  supported  in  WebKit/Blink   (chrome  +  safari  +  opera),  firefox  (gecko)  and   IE9  -­‐>   •  In  W3C  event  model,  it's  possible  to  register   as  many  event  handlers  as  you  like  for  the   same  event  on  one  element.  
  • 18. <a href="http://www.tamk.fi" id="mylink">Click Me!</a> <script> function showAlert1() { alert("click 1!"); } function showAlert2() { alert("click 2!"); } var link = window.document.getElementById("mylink"); link.addEventListener('click', showAlert1, false); link.addEventListener('click', showAlert2, false); </script>
  • 19. true  or  false?   •  The  boolean  value  (true,  false)  is  related  to  event   handling  order   •  If  an  element  and  one  of  its  ancestors  have  an   event  handler  for  the  same  event,  which  one   should  fire  first?   •  See   –  hYp://www.quirksmode.org/js/events_order.html   •  See  also  good  summary:   –  hYp://www.w3.org/wiki/ Handling_events_with_JavaScript