SlideShare una empresa de Scribd logo
1 de 19
Descargar para leer sin conexión
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	
  

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Intro to HTML & CSS
Intro to HTML & CSSIntro to HTML & CSS
Intro to HTML & CSS
 
JQuery introduction
JQuery introductionJQuery introduction
JQuery introduction
 
Html training slide
Html training slideHtml training slide
Html training slide
 
Javascript basics
Javascript basicsJavascript basics
Javascript basics
 
Introduction to HTML5
Introduction to HTML5Introduction to HTML5
Introduction to HTML5
 
JavaScript JQUERY AJAX
JavaScript JQUERY AJAXJavaScript JQUERY AJAX
JavaScript JQUERY AJAX
 
Java script ppt
Java script pptJava script ppt
Java script ppt
 
Jquery
JqueryJquery
Jquery
 
Document Object Model
Document Object ModelDocument Object Model
Document Object Model
 
JavaScript
JavaScriptJavaScript
JavaScript
 
jQuery for beginners
jQuery for beginnersjQuery for beginners
jQuery for beginners
 
Introduction To PHP
Introduction To PHPIntroduction To PHP
Introduction To PHP
 
Web Development with HTML5, CSS3 & JavaScript
Web Development with HTML5, CSS3 & JavaScriptWeb Development with HTML5, CSS3 & JavaScript
Web Development with HTML5, CSS3 & JavaScript
 
React JS - A quick introduction tutorial
React JS - A quick introduction tutorialReact JS - A quick introduction tutorial
React JS - A quick introduction tutorial
 
Web Services PHP Tutorial
Web Services PHP TutorialWeb Services PHP Tutorial
Web Services PHP Tutorial
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
 
HTML Basic, CSS Basic, JavaScript basic.
HTML Basic, CSS Basic, JavaScript basic.HTML Basic, CSS Basic, JavaScript basic.
HTML Basic, CSS Basic, JavaScript basic.
 
A History of PHP
A History of PHPA History of PHP
A History of PHP
 
An introduction to bootstrap
An introduction to bootstrapAn introduction to bootstrap
An introduction to bootstrap
 
Introduction into ES6 JavaScript.
Introduction into ES6 JavaScript.Introduction into ES6 JavaScript.
Introduction into ES6 JavaScript.
 

Destacado

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 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 Modeljay 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 qooxdooSebastian Werner
 
JavaScript From Scratch: Events
JavaScript From Scratch: EventsJavaScript From Scratch: Events
JavaScript From Scratch: EventsMichael Girouard
 
Yahoo presentation: JavaScript Events
Yahoo presentation: JavaScript EventsYahoo presentation: JavaScript Events
Yahoo presentation: JavaScript EventsPeter-Paul Koch
 
System model
System modelSystem model
System modelsoniaamim
 
JavaScript - An Introduction
JavaScript - An IntroductionJavaScript - An Introduction
JavaScript - An IntroductionManvendra Singh
 

Destacado (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 a JavaScript and BOM events

Speeding up mobile web apps
Speeding up mobile web appsSpeeding up mobile web apps
Speeding up mobile web appsIvano Malavolta
 
Fast Cordova applications
Fast Cordova applicationsFast Cordova applications
Fast Cordova applicationsIvano 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. WuAppUniverz Org
 
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 developmentzonathen
 
Learn javascript easy steps
Learn javascript easy stepsLearn javascript easy steps
Learn javascript easy stepsprince Loffar
 
Modern Web Technologies
Modern Web TechnologiesModern Web Technologies
Modern Web TechnologiesPerttu Myry
 
Javascript Update May 2013
Javascript Update May 2013Javascript Update May 2013
Javascript Update May 2013Ramesh Nair
 
Basic web security model
Basic web security modelBasic web security model
Basic web security modelG 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 dojoFu Cheng
 
jQuery - Chapter 1 - Introduction
 jQuery - Chapter 1 - Introduction jQuery - Chapter 1 - Introduction
jQuery - Chapter 1 - IntroductionWebStackAcademy
 
Javascript inside Browser (DOM)
Javascript inside Browser (DOM)Javascript inside Browser (DOM)
Javascript inside Browser (DOM)Vlad Mysla
 
Intro JavaScript
Intro JavaScriptIntro JavaScript
Intro JavaScriptkoppenolski
 
Mobile and IBM Worklight Best Practices
Mobile and IBM Worklight Best PracticesMobile and IBM Worklight Best Practices
Mobile and IBM Worklight Best PracticesAndrew Ferrier
 
Going Offline with JS
Going Offline with JSGoing Offline with JS
Going Offline with JSbrendankowitz
 

Similar a 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 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
 
Going Offline with JS
Going Offline with JSGoing Offline with JS
Going Offline with JS
 

Más de Jussi Pohjolainen

libGDX: Screens, Fonts and Preferences
libGDX: Screens, Fonts and PreferenceslibGDX: Screens, Fonts and Preferences
libGDX: Screens, Fonts and PreferencesJussi 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 AnimationJussi 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 libGDXJussi Pohjolainen
 
Advanced JavaScript Development
Advanced JavaScript DevelopmentAdvanced JavaScript Development
Advanced JavaScript DevelopmentJussi 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 AnimationJussi Pohjolainen
 
Implementing a Simple Game using libGDX
Implementing a Simple Game using libGDXImplementing a Simple Game using libGDX
Implementing a Simple Game using libGDXJussi Pohjolainen
 
Building Android games using LibGDX
Building Android games using LibGDXBuilding Android games using LibGDX
Building Android games using LibGDXJussi 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
 

Más de 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
 

Último

TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 

Último (20)

TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.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