Developer Snippet Diary

BOM In javascript

window.document.getElementById("header"); //SAME AS

document.getElementById("header");

  • window.innerHeight
  • window.innerWidth
  • window.open() - open a new window
  • window.close() - close the current window
  • window.moveTo() - move the current window
  • window.resizeTo() - resize the current window
  • screen.width
  • screen.height
  • screen.availWidth //withoaut taskbar etc
  • screen.availHeight
  • screen.colorDepth
  • screen.pixelDepth
  • window.location.href //href (URL) of the current page
  • window.location.hostname //domain name of the web host
  • window.location.pathname // path and filename of the current page
  • window.location.protocol //web protocol used (http: or https:)
  • window.location.assign("https://www.google.com") //loads a new document
  • window.history.back(); //same work as click on back button in browser
  • history.forward() //foward button
  • window.navigator: info about visitor's browser.
  • navigator.appName; //Netscape
  • navigator.appCodeName; //Mozilla
  • navigator.platform; //Win32
  • navigator.cookieEnabled; //true if cookies enabled
  • navigator.onLine; //true or false

ALERTS:

  • window.alert("sometext");
  • window.confirm("sometext"); //if click ok return true, else if click cancel return false
  • window.prompt("sometext","defaultText"); //for input some text

TIMING:

window.setInterval(function, milliseconds);//repeats execution of function after milliseconds

window.setTimeout(function, milliseconds); //execute function after milliseconds only one time

clearTimeout(myVar);  //if we want to cancel execution of setTimeout

 

Browser Object Model (BOM) allows JavaScript to "talk to" the browser.

All global JavaScript objects, functions, and variables automatically become members of the window object.

BOM USED TO

open/close windows,get screen info ie width,get locations,alerts,timings 

Posted by: R GONDAL
Email: rizikmw@gmail.com