How to use Javascript Window Object

Methods from Window Object

The windows object has the following properties and methods:

NameDescriptionReturns
alert(msg) Displays a message dialog window.void
blur()Unfocuses the window.void
clearInterval(id)Cancels an interval timer.void
clearTimeout(id)Cancels a timeout timer.void
close()Closes the window.void
confirm(msg) Displays a OK/Cancel prompt dialog.boolean
defaultViewReturns the Window for the active document.Window
documentReturns the Document object associated with this window.Document
focus()Focuses the window.void
framesReturns an array of the Window objects for the iframe elements.Window[]
historyReturns the browser history.History
innerHeightGets the height of the window content area.number
innerWidthGets the width window content area.number
lengthReturns the number of nested iframe elements in the document.number
locationReturns the current document's location.Location
openerReturns the Window that opened the current browsing context.Window
outerHeightGets the height of the window, including borders, menu bars, etc.number
outerWidthGets the width of the window, including borders, menu bars, etc.number
pageXOffetGets the number of pixels that the window has been scrolled horizontally from the topleft corner.number
pageYOffsetGets the number of pixels that the window has been scrolled vertically from the top-left corner.number
parentReturns the parent of the current Window.Window
postMessage(msg, origin)Sends the message to another document.void
print()Prompts the user to print the page.void
prompt(msg, val)Displays a dialog prompting the user to enter a value.string
screenReturns a Screen object describing the screen.Screen
screenLeft/screenXGets the number of pixels from the left edge of the window to the left edge of the screen.number
screenTop/screenYGets the number of pixels from the top edge of the window to the top edge of the screen.number
scrollBy(x, y)Scrolls the document relative to its current position.void
scrollTo(x, y)Scrolls to the specified position.void
selfReturns the Window for the current document.Window
setInterval(function, time)Creates a timer that will call the specified function every time milliseconds.int
setTimeout(function, time)Creates a timer that will call the specified function once after time milliseconds.int
showModalDialog() Displays a pop-up window showing the specified URL.void
stop()Stops the document loading.void
topReturns the top-most Window.Window

Window Events

The window object defines a wide range of events in the following table.

NameDescription
onabortTriggered when the loading of a document or resource is aborted.
onafterprintTriggered when the Window.print() method is called, before the user is presented with the print options.
onbeforeprintTriggered after the user has printed the document.
onerrorTriggered when there is an error loading a document or resource.
onhashchangeTriggered when the hash fragment changes.
onloadTriggered when the loading of a document or resource is complete.
onpopstateTriggered to provide a state object associated with the browser history.
onresizeTriggered when the window is resized.
onunloadTriggered when the document is unloaded from the window/browser.




















Home »
  Javascript »
    Javascript Reference »




Array
Canvas Context
CSSStyleDeclaration
CSSStyleSheet
Date
Document
Event
Global
History
HTMLElement
Input Element
Location
Math
Number
String
Window