Javascript Window


When the browser opens a document, it creates a window object that represents the window that is open in the browser.

Window object is a global object, you can attribute the window as a global variable to use. For example, you could just write document without writing window.document. Similarly, you can use the method of the current window object as a function, such as just writing alert(), without writing Window.alert().

If the document contains a frame, the browser creates a window object for the document and creates an additional window object for each frame.

Tip: Although there is no clear window of the relevant standards, but all browsers support the object.


Window object property

Properties Description Description
closed whether the window has been closed None
document For a read-only reference to the document object, see "JavaScript Document Object" /td> None
history For a read-only reference to the history object, see the JavaScript History object None
length Set or get the number of frames in the window None
location Location object for a window or frame, see "JavaScript Location object" None
name Set or get the name of the window None
navigator For a read-only reference to the Navigator object, see "JavaScript Navigator Objects" /td> None
opener Returns a reference to the window that created this window None
parent Returns the parent window, which is used to invoke the parent page object on the frame page None
screen For a read-only reference to the Screen object, see "JavaScript Screen" /td> None
self reference to the current window (own), generally omitted, with the window property None
top Returns the top-level ancestor window None
window reference to the current window (own), generally omitted, with the self attribute None
screenLeft A read-only integer representing the x-coordinate of the upper-left corner of the window on the screen IE, Safari, and Opera support
screenTop A read-only integer representing the y-coordinate of the upper-left corner of the window on the screen IE, Safari, and Opera support
screenX A read-only integer representing the x-coordinate of the upper-left corner of the window on the screen Firefox and Safari support
screenY A read-only integer representing the y-coordinate of the upper-left corner of the window on the screen Firefox and Safari support
defaultStatus Set or get the default text in the window's status bar Firefox does not support
status Set the text in the window's status bar Firefox does not support

Window object method

method Description Description
alert() displays an alert box, see "JavaScript alert" None
blur() Move the keyboard focus away from the top-level window Some browsers are invalid
clearInterval() Cancels the timeout set by the setInterval() method None
clearTimeout() Cancels the timeout set by the setTimeout() method None
close() Close the browser window None
confirm() To display a dialog box with an OK and a Cancel button, see the JavaScript confirm message confirmation box" None
focus() Give a window keyboard focus None
moveBy() Moves the window by the specified pixel relative to the current coordinates of the window None
moveTo() Moves the upper left corner of the window to a specified coordinate None
open() Open a new browser window or find a named window None
print() Print the contents of the current window None
prompt() Show a dialog box that accepts user input, see "JavaScript confirmation box" None
resizeBy() Resize the window by the specified pixel None
resizeTo() Resize the window according to the specified width and height None
scrollBy() Scrolls the content by the specified pixel value None
scrollTo() Scrolls the content to the specified coordinates None
setInterval() Calls a function or calculation expression for a specified millisecond period None
setTimeout() Calls a function or calculation expression after a specified number of milliseconds. None
createPopup() Create a pop-up window IE only support



Copyright 2014-2017 by DeveloperTut.com. All Rights Reserved.
TwitterGoogle+Facebook