JavaScript Tutorial

adplus-dvertising
Browsers In JavaScript
Previous Home Next

The browser provides us with a hierarchy of objects which we can use to control and access various information about time, screen, page, elements on a page etc.

All browsers are split into different parts i.e objects that can be accessed using Javascript. Collectively these parts are known as the Browser Object Model, or the BOM .

BOM is a pack of objects that allow to control the browser, e.g change current URL, access frames, do background requests to server with XMLHttpRequest etc. Functions like alert,confirm,prompt also belong BOM, they are provided by the browser.

The important javascript BOM are :

  • history object.
  • window object .
  • navigator object.
  • document object .
  • location object.
  • screen object.

history object :

The history object tracks what pages the user has visited in the current browser session. It is stored as a data stack that allows the user to use the Back and Forward buttons to move through the stack.

Methods of JavaScript history object :

Method Description
forward() To go one step forward in the history
back() loads the previous page.
length To return the items in the browser history
go() loads the given page number

window Object :

The window object represents the browser's frame or window, in which window is created automatically .

Methods of javascript window object :

Method Description
confirm() displays the confirm dialog box containing message with ok and cancel button
alert() displays the alert box containing message with ok button.
prompt() displays a dialog box to get input from the user.
close() its closes the current window.
open() its opens the new window.

Navigator Object:

The JavaScript window object property of navigator is used refer to the Navigator object, which contains all information related to browser, it vendor , version, plugins etc.

Methods of javascript Navigator Object :

Method Description
appName The name of the Browser.
appVersion Specifies the Version of the Browser.
appCodeName The Code name of the Browser.
platform The HTTP user-agent header sent from the browser to the server.
userAgent eturns the plugins. It is supported in Netscape and Firefox only.
cookieEnabled its returns true if cookie is enabled otherwise false
plugins its returns the plugins. It is supported in Netscape and Firefox only.
mimeTypes Array of MIME types registered with the browser.
Previous Home Next