JavaScripture
Contribute via GitHub Feedback

JavaScript Window : Global

Window is the global object in the browser that represents the browser window for the page. The window object itself is available through the window property and all properties on the Window are available directly in scripts. The Window object is also available as this in the root scope of a script (ie, outside of any Function).

Instance Properties

applicationCache : ApplicationCache  

crypto : Crypto
document : Document  

Returns the document for this window.

Example:

Run

Results:

 

external : External  

frameElement : Element  

frames : Window  

history : History  

Represents the user's browser history and allows the page to manipulate the history by adding pages or navigating between pages. See History for more details.

Example:

Run

Results:

 

length : Number  

localStorage : Storage  

localStorage allows saving data in the web browser that can be retrieved in future views of the web page. The data is saved across browser sessions and computer reboots. See also sessionStorage and Storage for more details.

Example:

Run

Results:

 

location : Location  

Describes the url of the current page. See Location for more details.

Example:

Run

Results:

 

name : String
navigator : Navigator

opener : Window

parent : Window  

self : Window  

Returns the global object for the browser. Also available through the window property and through this in the root scope.

Example:

Run

Results:

 

sessionStorage : Storage  

sessionStorage allows saving data in the web browser that can be retrieved in future views of the web page. The data is only saved for the current session, that is until the user closes the web browser. See also localStorage and Storage for more details.

Example:

Run

Results:

 

status : String

top : Window  

window : Window  

Returns the global object for the browser. Also available through the self property and through this in the root scope.

Example:

Run

Results:

 

Instance Methods

alert(message : String) : undefined

Displays a message box to the user with the specified message. Script execution is paused while the message box is displayed. See also confirm() and prompt().

Example:

Run

Results:

 

atob(unencoded : String) : String

Converts an ascii encoded string (base64) into a unicode/binary string. See also btob().

Example:

Run

Results:

 

blur() : undefined

btoa(encoded : String) : String

Converts a unicode/binary string into an ascii encoded string (base64). See also atob().

Example:

Run

Results:

 

cancelAnimationFrame(handle : Number) : undefined

Stops an animation frame callback from running. handle is the value returned by requestAnimationFrame().

Example:

Run

Results:

 

clearInterval(handle : Number) : undefined

Stops an setInterval() callback from running. handle is the value returned by setInterval().

Example:

Run

Results:

 

clearTimeout(handle : Number) : undefined

Stops a timeout from running. handle is the value returned by setTimeout().

Example:

Run

Results:

 

close() : undefined

confirm(message : String) : Boolean

Displays an Ok/Cancel message box to the user with the specified message. Returns true if the user clicked Ok. Script execution is paused while the message box is displayed. See also alert() and prompt().

Example:

Run

Results:

 

focus() : undefined

getComputedStyle(element : Element, [pseudoElement : String]) : CSSStyleDeclaration

Computes the effective style for element including all CSS rules that apply to element. See also element.style.

Example:

Run

Results:

 

open([url : String, [target = '_blank' : String, [features : String, [replace : Boolean]]]]) : Window

Opens the specified url.

url
the url to open.
target
must be one of: '_blank' (open in new window, the default), '_parent' (open in parent page/frame), '_self' (open in current page/frame), '_top' (open in top page), '<name>' (open in the window with the specified name).
features
is a comma separated list of '<name>=<value>' pairs where the valid names are 'left', 'top', 'height', 'width'.
replace
pass true to replace the contents instead of opening a new window.

print() : undefined

prompt(message : String, [default : String]) : String

Displays a message box containing an input box to the user with the specified message. The input box will be prepopulated with default if it is specified. Returns the String the user typed in the input box if the user clicks ok and null if they click cancel. Script execution is paused while the message box is displayed. See also alert() and confirm().

Example:

Run

Results:

 

requestAnimationFrame(callback : Function) : Number
callback(time : Number) : undefined

Schedules callback to be called before the next time the browser renders a frame to the screen. Must be called each time you'd like to schedule another frame. The time parameter to callback is the number of milliseconds since the page loaded. Returns a unique handle that can be passed to cancelAnimationFrame() to stop callback from being called.

Example:

Run

Results:

 

setInterval 2 variants
setInterval(callback : Function, [timeout : Number, [...]]) : Number

Schedules callback to be called repeatedly, every timeout milliseconds. Any extra parameters after timeout are passed to callback. Returns a unique handle that can be passed to clearInterval() to stop callback from being called. See also setTimeout() and requestAnimationFrame().

Example:

Run

Results:

 

setInterval(callback : String, [timeout : Number, [...]]) : Number

Same as setInterval() where the callback string is passed to eval when the time has elapsed.

setTimeout 2 variants
setTimeout(callback : String, [timeout = 0 : Number, [...]]) : Number

Same as setTimeout() where the callback string is passed to eval when the time has elapsed.

setTimeout(callback : Function, [timeout = 0 : Number, [...]]) : Number

Schedules callback to be called once after timeout milliseconds. Any extra parameters after timeout are passed to callback. Returns a unique handle that can be passed to clearTimeout() to stop callback from being called. See also setInterval() and requestAnimationFrame().

Example:

Run

Results:

 

showModalDialog(url : String, [arguments : Object]) : Object

stop() : undefined

Instance Events

onabort / 'abort'  
listener(event : Event) : undefined

onafterprint / 'afterprint'  
listener(event : Event) : undefined

onbeforeprint / 'beforeprint'  
listener(event : Event) : undefined

onbeforeunload / 'beforeunload'  
listener(event : BeforeUnloadEvent) : String

Called before the page is navigated away from. Return a non-empty String from listener to display a dialog box that gives the user the option to remain on the current page.

Example:

Run

Results:

 

onblur / 'blur'  
listener(event : Event) : undefined

oncanplay / 'canplay'  
listener(event : Event) : undefined

oncanplaythrough / 'canplaythrough'  
listener(event : Event) : undefined

onchange / 'change'  
listener(event : Event) : undefined

onclick / 'click'  
listener(event : Event) : undefined

oncontextmenu / 'contextmenu'  
listener(event : Event) : undefined

oncuechange / 'cuechange'  
listener(event : Event) : undefined

ondblclick / 'dblclick'  
listener(event : Event) : undefined

ondrag / 'drag'  
listener(event : Event) : undefined

ondragend / 'dragend'  
listener(event : Event) : undefined

ondragenter / 'dragenter'  
listener(event : Event) : undefined

ondragleave / 'dragleave'  
listener(event : Event) : undefined

ondragover / 'dragover'  
listener(event : Event) : undefined

ondragstart / 'dragstart'  
listener(event : Event) : undefined

ondrop / 'drop'  
listener(event : Event) : undefined

ondurationchange / 'durationchange'  
listener(event : Event) : undefined

onemptied / 'emptied'  
listener(event : Event) : undefined

onended / 'ended'  
listener(event : Event) : undefined

onerror / 'error'  
listener(event : Event, source : String, line : Number, column : Number) : undefined

onfocus / 'focus'  
listener(event : Event) : undefined

onhashchange / 'hashchange'  
listener(event : HashChangeEvent) : undefined

Fired when the '#' portion of the url changes. See also location.hash.

Example:

Run

Results:

 

oninput / 'input'  
listener(event : Event) : undefined

oninvalid / 'invalid'  
listener(event : Event) : undefined

onkeydown / 'keydown'  
listener(event : Event) : undefined

onkeypress / 'keypress'  
listener(event : Event) : undefined

onkeyup / 'keyup'  
listener(event : Event) : undefined

onload / 'load'  
listener(event : Event) : undefined

onloadeddata / 'loadeddata'  
listener(event : Event) : undefined

onloadedmetadata / 'loadedmetadata'  
listener(event : Event) : undefined

onloadstart / 'loadstart'  
listener(event : Event) : undefined

onmessage / 'message'  
listener(event : Event) : undefined

onmousedown / 'mousedown'  
listener(event : Event) : undefined

onmousemove / 'mousemove'  
listener(event : Event) : undefined

onmouseout / 'mouseout'  
listener(event : Event) : undefined

onmouseover / 'mouseover'  
listener(event : Event) : undefined

onmouseup / 'mouseup'  
listener(event : Event) : undefined

onmousewheel / 'mousewheel'  
listener(event : Event) : undefined

onoffline / 'offline'  
listener(event : Event) : undefined

ononline / 'online'  
listener(event : Event) : undefined

onpause / 'pause'  
listener(event : Event) : undefined

onplay / 'play'  
listener(event : Event) : undefined

onplaying / 'playing'  
listener(event : Event) : undefined

onpagehide / 'pagehide'  
listener(event : Event) : undefined

onpageshow / 'pageshow'  
listener(event : Event) : undefined

onpopstate / 'popstate'  
listener(event : PopStateEvent) : undefined

Called when the page navigation changes. See also History.

onprogress / 'progress'  
listener(event : Event) : undefined

onratechange / 'ratechange'  
listener(event : Event) : undefined

onreset / 'reset'  
listener(event : Event) : undefined

onresize / 'resize'  
listener(event : Event) : undefined

onscroll / 'scroll'  
listener(event : Event) : undefined

onseeked / 'seeked'  
listener(event : Event) : undefined

onseeking / 'seeking'  
listener(event : Event) : undefined

onselect / 'select'  
listener(event : Event) : undefined

onshow / 'show'  
listener(event : Event) : undefined

onstalled / 'stalled'  
listener(event : Event) : undefined

onstorage / 'storage'  
listener(event : Event) : undefined

onsubmit / 'submit'  
listener(event : Event) : undefined

onsuspend / 'suspend'  
listener(event : Event) : undefined

ontimeupdate / 'timeupdate'  
listener(event : Event) : undefined

onunload / 'unload'  
listener(event : Event) : undefined

onvolumechange / 'volumechange'  
listener(event : Event) : undefined

onstorage / 'storage'  
listener(event : StorageEvent) : undefined