JavaScripture
Contribute via GitHub Feedback

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
customElements : CustomElementRegistry  

Provides a way to extend HTML/DOM with your own elements that have custom logic similar to built in elements. See also CustomElementPrototype.

Example:

Run

Results:

 

document : Document  

Returns the document for this window.

Example:

Run

Results:

 

external : External  

frameElement : Element  

frames : Window  

globalThis : Window  

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

Example:

Run

Results:

 

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:

 

indexedDB : IDBFactory

innerHeight : Number  

Height of the browser window in CSS pixels excluding any browser chrome.

Example:

Run

Results:

 

innerWidth : Number  

Width of the browser window in CSS pixels exluding any browser chrome.

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

outerHeight : Number  

Height of the browser window in CSS pixels including any browser chrome.

Example:

Run

Results:

 

outerWidth : Number  

Width of the browser window in CSS pixels including any browser chrome.

Example:

Run

Results:

 

pageXOffset : Number  
pageYOffset : Number  
parent : Window  

screen : Screen  
screenX : Number  

X position of the top left corner of the browser in pixels. See screen for details about the size of the screen.

Example:

Run

Results:

 

screenY : Number  

Y position of the top left corner of the browser in pixels. See screen for details about the size of the screen.

Example:

Run

Results:

 

scrollX : Number  
scrollY : Number  
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, through this in the root scope, and through the globalThis property (in ECMAScript 2020).

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:

 

createImageBitmap 13 variants
createImageBitmap(source : HTMLImageElement) : Promise<ImageBitmap>

Example:

Run

Results:

 

createImageBitmap(source : HTMLVideoElement) : Promise<ImageBitmap>

Example:

Run

Results:

 

createImageBitmap(source : HTMLCanvasElement) : Promise<ImageBitmap>

Example:

Run

Results:

 

createImageBitmap(source : Blob) : Promise<ImageBitmap>

Example:

Run

Results:

 

createImageBitmap(source : ImageData) : Promise<ImageBitmap>

Example:

Run

Results:

 

createImageBitmap(source : HTMLImageElement, [options : Object]) : Promise<ImageBitmap>
options : {
imageOrientation :StringOne of 'none' or 'flipY'. Default is 'none'.
premultiplyAlpha :StringOne of 'none', 'premultiply', or 'default'. Default is 'default'.
colorSpaceConversion :StringOne of 'none' or 'default'. Default is 'default'.
resizeWidth :Number
resizeHeight :Number
resizeQuality :StringOne of 'pixelated', 'low', 'medium', or 'high'. Default is 'low'.
}

Example:

Run

Results:

 

createImageBitmap(source : HTMLVideoElement, [options : Object]) : Promise<ImageBitmap>
options : {
imageOrientation :StringOne of 'none' or 'flipY'. Default is 'none'.
premultiplyAlpha :StringOne of 'none', 'premultiply', or 'default'. Default is 'default'.
colorSpaceConversion :StringOne of 'none' or 'default'. Default is 'default'.
resizeWidth :Number
resizeHeight :Number
resizeQuality :StringOne of 'pixelated', 'low', 'medium', or 'high'. Default is 'low'.
}

Example:

Run

Results:

 

createImageBitmap(source : HTMLCanvasElement, [options : Object]) : Promise<ImageBitmap>
options : {
imageOrientation :StringOne of 'none' or 'flipY'. Default is 'none'.
premultiplyAlpha :StringOne of 'none', 'premultiply', or 'default'. Default is 'default'.
colorSpaceConversion :StringOne of 'none' or 'default'. Default is 'default'.
resizeWidth :Number
resizeHeight :Number
resizeQuality :StringOne of 'pixelated', 'low', 'medium', or 'high'. Default is 'low'.
}

Example:

Run

Results:

 

createImageBitmap(source : Blob, [options : Object]) : Promise<ImageBitmap>
options : {
imageOrientation :StringOne of 'none' or 'flipY'. Default is 'none'.
premultiplyAlpha :StringOne of 'none', 'premultiply', or 'default'. Default is 'default'.
colorSpaceConversion :StringOne of 'none' or 'default'. Default is 'default'.
resizeWidth :Number
resizeHeight :Number
resizeQuality :StringOne of 'pixelated', 'low', 'medium', or 'high'. Default is 'low'.
}

Example:

Run

Results:

 

createImageBitmap(source : ImageData, [options : Object]) : Promise<ImageBitmap>
options : {
imageOrientation :StringOne of 'none' or 'flipY'. Default is 'none'.
premultiplyAlpha :StringOne of 'none', 'premultiply', or 'default'. Default is 'default'.
colorSpaceConversion :StringOne of 'none' or 'default'. Default is 'default'.
resizeWidth :Number
resizeHeight :Number
resizeQuality :StringOne of 'pixelated', 'low', 'medium', or 'high'. Default is 'low'.
}

Example:

Run

Results:

 

createImageBitmap(source : ImageBitmap, [options : Object]) : Promise<ImageBitmap>
options : {
imageOrientation :StringOne of 'none' or 'flipY'. Default is 'none'.
premultiplyAlpha :StringOne of 'none', 'premultiply', or 'default'. Default is 'default'.
colorSpaceConversion :StringOne of 'none' or 'default'. Default is 'default'.
resizeWidth :Number
resizeHeight :Number
resizeQuality :StringOne of 'pixelated', 'low', 'medium', or 'high'. Default is 'low'.
}

Example:

Run

Results:

 

createImageBitmap(source : HTMLImageElement, sx : Number, sy : Number, sw : Number, sh : Number) : Promise<ImageBitmap>

Example:

Run

Results:

 

createImageBitmap(source : HTMLImageElement, sx : Number, sy : Number, sw : Number, sh : Number, [options : Object]) : Promise<ImageBitmap>
options : {
imageOrientation :StringOne of 'none' or 'flipY'. Default is 'none'.
premultiplyAlpha :StringOne of 'none', 'premultiply', or 'default'. Default is 'default'.
colorSpaceConversion :StringOne of 'none' or 'default'. Default is 'default'.
resizeWidth :Number
resizeHeight :Number
resizeQuality :StringOne of 'pixelated', 'low', 'medium', or 'high'. Default is 'low'.
}

Example:

Run

Results:

 

fetch 2 variants
fetch(request : Request, [requestInit : Object]) : Promise<Response>

Fetches the specified web request. If requestInit is specified, its values overwrite the values on request. See also Request and Response.

Example:

Run

Results:

 

fetch(url : String, [requestInit : Object]) : Promise<Response>

Fetches the specified url. See also Request and Response.

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:

 

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

Opens a new tab or window for the specified url.

url
the url to open or '' to open an empty window.
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.

Example:

Run

Results:

 

postMessage(message : Object, expectedOrigin : String, [transfer : Array<Transferable>]) : undefined

Sends message to this (usually something other than the global window, like the parent, iframe contentwindow, or return value of open()). The message will be available in the MessageEvent.data property on the event passed to the onmessage event listener. To ensure the window's content has not changed while the message is in flight, expectedOrigin must match this.origin (or be '*' to ignore check and possibly send the message to another site). The elements of objectsToTransfer will be transferred to the JavaScript context that owns this and no longer available in the context that called postMessage().

See also BroadcastChannel and MessageChannel.

Example:

Run

Results:

 

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:

 

reportError(error : Object) : undefined

Fires the error event with the specified error. Unlike throw error, this will always cause the error event to fire, even if there is a catch handler around the call.

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 : 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:

 

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

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

showDirectoryPicker([options : Object]) : Promise<FileSystemDirectoryHandle>
options : {
id :String
startIn :ObjectEither a String or FileSystemHandle
}

Specifying options.id will cause the browser to remember the directory of the chosen file so another call to showSaveFilePicker with the same id will start in that directory.

Example:

Run

Results:

 

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

showOpenFilePicker([options : Object]) : Promise<Array<FileSystemFileHandle>>
options : {
excludeAcceptAllOption :Boolean
id :String
multiple :Boolean
startIn :ObjectEither a String or FileSystemHandle
types :Array
}

Specifying options.id will cause the browser to remember the directory of the chosen file so another call to showSaveFilePicker with the same id will start in that directory. See spec for complete details.

Example:

Run

Results:

 

showSaveFilePicker([options : Object]) : Promise<FileSystemFileHandle>
options : {
excludeAcceptAllOption :Boolean
id :String
multiple :Boolean
startIn :ObjectEither a String or FileSystemHandle
suggestedName :String
types :Array
}

Specifying options.id will cause the browser to remember the directory of the chosen file so another call to showSaveFilePicker with the same id will start in that directory.

Example:

Run

Results:

 

stop() : undefined

structuredClone(value : Object, [transfer : Array<Transferable>]) : Object

Creates a deep clone of value. Elements of value in transfer will be transferred to the new object and will no longer be useable on value.

Example:

Run

Results:

 

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

oncopy / 'copy'  
listener(event : ClipboardEvent) : undefined
oncuechange / 'cuechange'  
listener(event : Event) : undefined

oncut / 'cut'  
listener(event : ClipboardEvent) : 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(message : string, source : String, line : Number, column : Number, error : Object) : undefined

Fired when an unhandled exception is thrown or an error is passed to reportError().

Example:

Run

Results:

 

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

ongamepadconnected / 'gamepadconnected'  
listener(event : GamepadEvent) : undefined

Example:

Run

Results:

 

ongamepaddisconnected / 'gamepaddisconnected'  
listener(event : GamepadEvent) : undefined

Example:

Run

Results:

 

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

Fired when postMessage() is called on this.

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

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

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

onpaste / 'paste'  
listener(event : ClipboardEvent) : undefined
onpause / 'pause'  
listener(event : Event) : undefined

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

onplaying / 'playing'  
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 : StorageEvent) : undefined

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

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

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

onunhandledrejection / 'unhandledrejection'  
listener(event : PromiseRejectionEvent) : undefined

Fired when a Promise's reject handler is called or an exception is thrown in an Promise executor function or in an async function.

Example:

Run

Results:

 

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

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