Javascript: Bom and Dom
Javascript: Bom and Dom
Javascript: Bom and Dom
17-Feb-20
BOM vs DOM
2
The “window” Object
It is the highest-level object in the JavaScript browser
object hierarchy.
It is the default object and is created automatically when
a page is loaded.
Since it is the default object, we may omit writing
window explicitly.
document.write(“a test message”);
window.document.write(“a test message”);
It also includes several properties and methods for us to
manipulate the webpage.
5
Window Object
Methods :- alter(), blur(), clearInterval(),
clearTimeout(), close(), conform(), focus(), moveBy(),
moveTo(), open(), prompt(), resizeTo(), scroll(),
scrollTo(), scrollBy(), setInterval(), setTimeout().
Properties:- closed, defaultStatus, document, frames
array, history property, location, name, navigator,
opener, parent, screen , status, top.
6
OPEN URL
<script type="text/javascript">
function msg(){
open("http://www.w3school.com");
}
</script>
<input type="button" value=“w3" onclick="msg()"/>
7
8
9
setTimeout/clearTimeout
setTimeout(function, milliseconds) -Executes a function,
after waiting a specified number of milliseconds.
setInterval(function, milliseconds) - Same as setTimeout(),
but repeats the execution of the function continuously.
<input type="button" value="click" onclick=“var t =
setTimeout( function(){alert("Welcome msg after 2s")
},2000)”>
<input type="button" value=“stop" onclick =
"clearTimeout(t)”>
10
Window object
11
Location
location.assign("http://www.w3schools.com");
location.replace("http://www.w3schools.com");
location.reload();
Method Description
assign() Loads a new document
reload() Reloads the current document
replace() Replaces the current document with a new one
12
History
history.back();//for previous page
history.forward();//for next page
13
Navigator
<script>
document.writeln("<br/>navigator.appCodeName: "+navigator.appCodeName);
document.writeln("<br/>navigator.appName: "+navigator.appName);
document.writeln("<br/>navigator.appVersion: "+navigator.appVersion);
document.writeln("<br/>navigator.cookieEnabled: "+navigator.cookieEnabled);
document.writeln("<br/>navigator.language: "+navigator.language);
document.writeln("<br/>navigator.userAgent: "+navigator.userAgent);
document.writeln("<br/>navigator.platform: "+navigator.platform);
document.writeln("<br/>navigator.onLine: "+navigator.onLine);
</script>
14
Screen
Property Description
availHeight Returns the height of the screen (excluding the Windows Taskbar)
availWidth Returns the width of the screen (excluding the Windows Taskbar)
colorDepth Returns the bit depth of the color palette for displaying images
height Returns the total height of the screen
pixelDepth Returns the color resolution (in bits per pixel) of the screen
width Returns the total width of the screen
15
<html>
<body>
<h3>Your Screen:</h3>
<div id="demo"></div>
<script>
var txt = "";
txt += "<p>Total width/height: " + screen.width + "*" + screen.height + "</p>";
txt += "<p>Available width/height: " + screen.availWidth + "*" + screen.availHeight +
"</p>";
txt += "<p>Color depth: " + screen.colorDepth + "</p>";
txt += "<p>Color resolution: " + screen.pixelDepth + "</p>";
document.getElementById("demo").innerHTML = txt;
</script>
</body>
</html>
16