| Right click this window and select "view source" in order to copy the source for this script.
Window Object
The Window object is the top level object in JavaScript, and contains in
itself several other objects, such as "document", "history" etc.
Events
Events |
Description |
onblur |
Code is executed when the window loses
focus. |
onerror |
Code is executed when a JavaScript
error occurs. |
onfocus |
Code is executed when the focus is set
on the current window. |
onload |
Code is executed when the page has
finished loading. |
onresize |
Code is executed when the window is
resized. |
onunload |
Code is executed when the page is
unloaded (visitor leaves the page). |
*Most of the events above can be defined in two ways. Using "onload" as an
example:
<body onload="dothis()">
window.onload=dothis //inside your script
Properties
Properties |
Description |
closed |
Returns the Boolean variable
indicating whether window has been closed or not. |
defaultStatus |
Read/write property that reflects the
default window status bar message that appears. |
document |
Reference to the current document
object. |
frames |
An array referencing all of the frames
in the current window. Use frames.length to probe the number of
frames. |
history |
Reference to the History object of
JavaScript, which contains information on the URLs the visitor has
visited within the window. |
length |
Returns the number of frames contained
in the window. |
location |
Reference to the Location object of
JavaScript, which contains information on the current URL. |
name |
The name of the window as optionally
specified when calling window.open(). |
opener |
Contains a reference to the window
that opened the secondary window via window.open(). This property
should be invoked in the secondary window. |
parent |
Reference to the parent window of the
current window, assuming current window is a frame. Otherwise, it
simply refers to current window. |
self |
A synonym for the current window. |
status |
A read/write property that allows you
to probe and write to the browser's status bar. |
top |
A synonym for the topmost browser
window. |
window |
References the current window. Same as
"self." |
innerWidth, innerHeight |
Specifies the width and height, in
pixels, of the window's content area respectively. Read/Write. Does
not include the toolbar, scrollbars etc. NS4 and NS6+ only.
Note: IE4+ equivalents are "document.body.clientWidth" and
"document.body.clientHeight" |
outerWidth, outerHeight |
Specifies the total width and height,
in pixels, of the window's content area respectively. Read/Write.
Includes any toolbar, scrollbars etc. NS4 and NS6+ only. |
pageXOffset, pageYOffset |
Returns an integer representing the
pixels the current document has been scrolled from the upper left
corner of the window, horizontally and vertically, respectively.
NS4 and NS6+ only. Note: IE4+ equivalents are
"document.body.scrollLeft" and "document.body.scrollTop" |
screenX, screenY |
Specifies the x and y coordinates of
the window relative to the user's monitor screen. NS4 and NS6+
only. |
screenLeft, screenTop |
Specifies the x and y coordinates of
the window relative to the user's monitor screen. IE5+ only. |
Methods
Note:
"[]" surrounding a parameter below means the parameter is optional.
Methods |
Description |
alert(msg) |
Displays an Alert dialog
box with the desired message and OK button. |
blur() |
Removes focus from the
window in question, sending the window to the background on the
user's desktop. |
clearInterval(ID) |
Clears the timer set
using ID=setInterval(). |
clearTimeout(ID) |
Clears the timer set
using ID=setTimeout(). |
close() |
Closes a window. |
confirm(msg) |
Displays a Confirm dialog
box with the specified message and OK and Cancel buttons.
Example(s) |
find(string,
[casesensitive], [backward]) |
Searches for the "string"
within the page, and returns string or false, accordingly.
"casesensitive" is a Boolean denoting whether search is case
sensitive. "backwards" is a Boolean when set to true, searches the
page backwards. Final two optional parameters must be set together
or none at all. NS4/NS6+ exclusive method. |
focus() |
Sets focus to the window,
bringing it to the forefront on the desktop. |
home() |
Navigates the window to
the homepage as designated by the user's browser setting. NS4/NS6+
only. |
moveBy(dx, dy) |
Moves a window by the
specified amount in pixels. |
moveTo(x, y) |
Moves a window to the
specified coordinate values, in pixels. |
open(URL, [name],
[features], [replace]) |
Opens a new browser
window. "Name" argument specifies a name that you can use in the
target attribute of your <a> tag. "Features" allows you to show/hide
various aspects of the window interface. "Replace" is a Boolean
argument that denotes whether the URL loaded into the new window
should add to the window's history list. A value of true causes URL
to not be added. Example(s) |
print() |
Prints the contents of
the window or frame. |
prompt(msg, [input]) |
Displays a Prompt dialog
box with a message. Optional "input" argument allows you to specify
the default input (response) that gets entered into the dialog box.
Set "input" to "" to create a blank input field.
Example(s) |
resizeBy(dx, dy) |
Resizes a window by the
specified amount in pixels. |
resizeTo(x y) |
Resizes a window to the
specified pixel values. |
scrollBy(dx, dy) |
Scrolls a window by the
specified amount in pixels. |
scrollTo(x, y) |
Scrolls a window to the
specified pixel values. |
setInterval("func",
interval, [args]) |
Calls the specified
"func" (or a JavaScript statement) repeatedly per the "interval"
interval, in milliseconds (ie: 1000=every 1 second). "func" must be
surrounded in quotations, as if it was a string. Use the optional
"args" to pass any number of arguments to the function. |
setTimeout("func",
interval) |
Calls the specified
"func" (or a JavaScript statement) once after "interval" has
elapsed, in milliseconds (ie: 1000=after 1 second). "func" must be
surrounded in quotations, as if it was a string. |
stop() |
Stops the window from
loading. NS4/NS6+ exclusive method. |
Window Features in window.open()
The below lists the string features you can pass into the "feature"
parameter of window.open() to manipulate its interface. Most features
support a value of true or false, though in general, simply including the
name of the feature implies it should be added to the window (yes), while
not including it means it shouldn't (no). Separate each feature with a
comma (,).
Feature |
Description |
channelmode |
Specifies if window should be opened
in channel mode. IE only. |
fullscreen |
Specifies if window should be opened
in full screen mode. IE only. |
height |
Specifies the height of the window. |
left |
Specifies the x coordinates of the
window in pixels. IE only. See "screenX" as well. |
location |
Specifies if the location bar of the
window should be included. |
menubar |
Specifies if the menu bar of the
window should be included. |
resizable |
Specifies if window should be
resizable. |
screenX |
Specifies the x coordinates of the
window in pixels. NS only. See "left" as well. |
screenY |
Specifies the x coordinates of the
window in pixels. NS only. See "top" as well. |
scrollbars |
Specifies if window should contain
scrollbars. |
status |
Specifies if the status bar of the
window should be included. |
toolbar |
Specifies if the toolbar of the window
(ie: reload button) should be included. |
top |
Specifies the y coordinates of the
window in pixels. IE only. See "screenY" as well. |
width |
Specifies the width of the window. |
Examples
open(URL, [name],
[features], [replace])
window.open("http://www.dynamicdrive.com", "",
"width=800px, height=600px, resizable")
confirm(msg)
var yourstate=window.confirm("Are you sure you are ok?")
if (yourstate) //Boolean variable. Sets to true if user pressed "OK" versus
"Cancel."
window.alert("Good!")
prompt(msg, [input])
var thename=window.prompt("please enter your name")
window.alert(thename)
|