Saturday, August 2, 2014

JavaScript Browsers Object Model (BOM) Screen and Window

-Objects:

  • we know that Objects are special type of variables that have a special methods and properties and you can check out our article about it Objects in JavaScript 
-BOM:

  • Browsers objects model it makes the JavaScript code connect with the browser and talk with it
  • since most of the browsers have been implemented almost the same of JavaScript code 
-Window Object:

  • supported by all browsers:Google Chrome,Firefox,Safari......etc
  • All Global variables and functions has been written in the JavaScript code are methods and properties for the Window object lets see this example:
here x is a global variable that can be seen and used from all functions in the script and as we said before the Window object will see x as a property so we can use it when ever we want.
  • even the Document object is a property of the Window Object
-Window Object Properties:

  • Width: if you want to get the width or our window browser you can use this property of the window Object .
  • Height: gives you the value of window height
  • lets see this example:


-Window Object Methods:
  • window.open(): it opens a new window "tab" for browsers and you can make this new window open any url you want just pass it by a parameter to this method:

window.close(): this method is used to close the current widow you are opening:
this is the most important things for the Window Object.
-Screen Object:


  • there's a bit difference between the Window and Screen because for Screen object you can open a new tab or close a one you can just get the color depths and the pixels and that's what the Window object cant do.
  • the common thing between Window and Screen objects that they both can give you the width and height.
  • if you do this: this will give you the same value
Screen Object properties :

  • screen.width: gives us the screen width 
  • screen.height: what do you think :) it'll show us the value of the screen height 
  • screen.pixelDepth: it'll return the pixel depths value
  • screen,colorDepth: gives you the color depths of the screen
-Related to this post:


Thank you all guys

No comments:

Post a Comment