1. 8 Web application APIs
    1. 8.1 Scripting
      1. 8.1.1 Introduction
      2. 8.1.2 Agents and agent clusters
        1. 8.1.2.1 Integration with the JavaScript agent formalism
        2. 8.1.2.2 Integration with the JavaScript agent cluster formalism
      3. 8.1.3 Script processing model
        1. 8.1.3.1 Runtime script errors
        2. 8.1.3.2 Unhandled promise rejections
        3. 8.1.3.3 Module-related host hooks
      4. 8.1.4 Event loops
      5. 8.1.5 Events
        1. 8.1.5.1 Event handlers
        2. 8.1.5.2 Event handlers on elements, Document objects, and Window objects
    2. 8.2 The WindowOrWorkerGlobalScope mixin
    3. 8.3 Base64 utility methods

8 Web application APIs

8.1 Scripting

8.1.1 Introduction

Various mechanisms can cause author-provided executable code to run in the context of a document. These mechanisms include, but are probably not limited to:

8.1.2 Agents and agent clusters

8.1.2.1 Integration with the JavaScript agent formalism

JavaScript defines the concept of an agent. This section gives the mapping of that language-level concept on to the web platform.

Conceptually, the agent concept is an architecture-independent, idealized "thread" in which JavaScript code runs. Such code can involve multiple globals/realms that can synchronously access each other, and thus needs to run in a single execution thread.

The following types of agents exist on the web platform:

Similar-origin window agent

Contains various Window objects which can potentially reach each other, either directly or by using document.domain.

If the encompassing agent cluster's cross-origin isolated is true, then all the Window objects will be same origin, can reach each other directly, and document.domain will no-op.

Two Window objects that are same origin can be in different similar-origin window agents, for instance if they are each in their own browsing context group.

Dedicated worker agent

Contains a single DedicatedWorkerGlobalScope.

Shared worker agent

Contains a single SharedWorkerGlobalScope.

Service worker agent

Contains a single ServiceWorkerGlobalScope.

Worklet agent

Contains a single WorkletGlobalScope object.

Although a given worklet can have multiple realms, each such realm needs its own agent, as each realm can be executing code independently and at the same time as the others.

Only shared and dedicated worker agents allow the use of JavaScript Atomics APIs to potentially block.

8.1.2.2 Integration with the JavaScript agent cluster formalism

JavaScript also defines the concept of an agent cluster, which this standard maps to the web platform by placing agents appropriately when they are created.

The agent cluster concept is crucial for defining the JavaScript memory model, and in particular among which agents the backing data of SharedArrayBuffer objects can be shared.

Conceptually, the agent cluster concept is an architecture-independent, idealized "process boundary" that groups together multiple "threads" (agents). The agent clusters defined by the specification are generally more restrictive than the actual process boundaries implemented in user agents. By enforcing these idealized divisions at the specification level, we ensure that web developers see interoperable behavior with regard to shared memory, even in the face of varying and changing user agent process models.

The following pairs of global objects are each within the same agent cluster, and thus can use SharedArrayBuffer instances to share memory with each other:

The following pairs of global objects are not within the same agent cluster, and thus cannot share memory:

8.1.3 Script processing model

8.1.3.1 Runtime script errors

In various scenarios, the user agent can report an exception by firing an error event at the Window. If this event is not canceled, then the error is considered not handled, and can be reported to the developer console.

8.1.3.2 Unhandled promise rejections

Window/rejectionhandled_event

Support in all current engines.

Firefox69+Safari11+Chrome49+
Opera36+Edge79+
Edge (Legacy)NoInternet ExplorerNo
Firefox Android🔰 68+Safari iOS11.3+Chrome Android49+WebView Android49+Samsung Internet5.0+Opera Android36+
caniuse.com table

Window/unhandledrejection_event

Support in all current engines.

Firefox69+Safari11+Chrome49+
Opera36+Edge79+
Edge (Legacy)NoInternet ExplorerNo
Firefox Android🔰 68+Safari iOS11.3+Chrome Android49+WebView Android49+Samsung Internet5.0+Opera Android36+
caniuse.com table

In addition to synchronous runtime script errors, scripts may experience asynchronous promise rejections, tracked via the unhandledrejection and rejectionhandled events.

8.1.3.3 Module-related host hooks

The JavaScript specification defines a syntax for modules, as well as some host-agnostic parts of their processing model. This specification defines the rest of their processing model: how the module system is bootstrapped, via the script element with type attribute set to "module", and how modules are fetched, resolved, and executed. [JAVASCRIPT]

Although the JavaScript specification speaks in terms of "scripts" versus "modules", in general this specification speaks in terms of classic scripts versus module scripts, since both of them use the script element.

modulePromise = import(specifier)

Returns a promise for the module namespace object for the module script identified by specifier. This allows dynamic importing of module scripts at runtime, instead of statically using the import statement form. The specifier will be resolved relative to the active script's base URL.

The returned promise will be rejected if an invalid specifier is given, or if a failure is encountered while fetching or evaluating the resulting module graph.

This syntax can be used inside both classic and module scripts. It thus provides a bridge into the module-script world, from the classic-script world.

url = import . meta . url

Returns the active module script's base URL.

This syntax can only be used inside module scripts.

Module maps are used to ensure that imported JavaScript modules are only fetched, parsed, and evaluated once per Document or worker.

Since module maps are keyed by URL, the following code will create three separate entries in the module map, since it results in three different URLs:

import "https://example.com/module.mjs";
import "https://example.com/module.mjs#map-buster";
import "https://example.com/module.mjs?debug=true";

That is, URL queries and fragments can be varied to create distinct entries in the module map; they are not ignored. Thus, three separate fetches and three separate module evaluations will be performed.

In contrast, the following code would only create a single entry in the module map, since after applying the URL parser to these inputs, the resulting URL records are equal:

import "https://example.com/module2.mjs";
import "https:example.com/module2.mjs";
import "https://///example.com\\module2.mjs";
import "https://example.com/foo/../module2.mjs";

So in this second example, only one fetch and one module evaluation will occur.

Note that this behavior is the same as how shared workers are keyed by their parsed constructor url.

The following are valid module specifiers:

The following are valid module specifiers according to the above algorithm, but will invariably cause failures when they are fetched:

The following are not valid module specifiers according to the above algorithm:

8.1.4 Event loops

To coordinate events, user interaction, scripts, rendering, networking, and so forth, user agents must use event loops as described in this section. Each agent has an associated event loop, which is unique to that agent.

The event loop of a similar-origin window agent is known as a window event loop. The event loop of a dedicated worker agent, shared worker agent, or service worker agent is known as a worker event loop. And the event loop of a worklet agent is known as a worklet event loop.

Event loops do not necessarily correspond to implementation threads. For example, multiple window event loops could be cooperatively scheduled in a single thread.

However, for the various worker agents that are allocated with [[CanBlock]] set to true, the JavaScript specification does place requirements on them regarding forward progress, which effectively amount to requiring dedicated per-agent threads in those cases.

8.1.5 Events

8.1.5.1 Event handlers

Events/Event_handlers

Many objects can have event handlers specified. These act as non-capture event listeners for the object on which they are specified. [DOM]

Event handlers are exposed in two ways.

The first way, common to all event handlers, is as an event handler IDL attribute.

The second way is as an event handler content attribute. Event handlers on HTML elements and some of the event handlers on Window objects are exposed in this way.

For both of these two ways, the event handler is exposed through a name, which is a string that always starts with "on" and is followed by the name of the event for which the handler is intended.


Most of the time, the object that exposes an event handler is the same as the object on which the corresponding event listener is added. However, the body and frameset elements expose several event handlers that act upon the element's Window object, if one exists. In either case, we call the object an event handler acts upon the target of that event handler.


An event handler IDL attribute is an IDL attribute for a specific event handler. The name of the IDL attribute is the same as the name of the event handler.


An event handler content attribute is a content attribute for a specific event handler. The name of the content attribute is the same as the name of the event handler.

Event handler content attributes, when specified, must contain valid JavaScript code which, when parsed, would match the FunctionBody production after automatic semicolon insertion.

This example demonstrates the order in which event listeners are invoked. If the button in this example is clicked by the user, the page will show four alerts, with the text "ONE", "TWO", "THREE", and "FOUR" respectively.

<button id="test">Start Demo</button>
<script>
 var button = document.getElementById('test');
 button.addEventListener('click', function () { alert('ONE') }, false);
 button.setAttribute('onclick', "alert('NOT CALLED')"); // event handler listener is registered here
 button.addEventListener('click', function () { alert('THREE') }, false);
 button.onclick = function () { alert('TWO'); };
 button.addEventListener('click', function () { alert('FOUR') }, false);
</script>

However, in the following example, the event handler is deactivated after its initial activation (and its event listener is removed), before being reactivated at a later time. The page will show five alerts with "ONE", "TWO", "THREE", "FOUR", and "FIVE" respectively, in order.

<button id="test">Start Demo</button>
<script>
 var button = document.getElementById('test');
 button.addEventListener('click', function () { alert('ONE') }, false);
 button.setAttribute('onclick', "alert('NOT CALLED')"); // event handler is activated here
 button.addEventListener('click', function () { alert('TWO') }, false);
 button.onclick = null;                                 // but deactivated here
 button.addEventListener('click', function () { alert('THREE') }, false);
 button.onclick = function () { alert('FOUR'); };       // and re-activated here
 button.addEventListener('click', function () { alert('FIVE') }, false);
</script>

The EventHandler callback function type represents a callback used for event handlers.

In JavaScript, any Function object implements this interface.

For example, the following document fragment:

<body onload="alert(this)" onclick="alert(this)">

...leads to an alert saying "[object Window]" when the document is loaded, and an alert saying "[object HTMLBodyElement]" whenever the user clicks something in the page.

The return value of the function affects whether the event is canceled or not: if the return value is false, the event is canceled.

There are two exceptions in the platform, for historical reasons:

For historical reasons, the onerror handler has different arguments:

window.onerror = (message, source, lineno, colno, error) => {};

Similarly, the onbeforeunload handler has a different return value: it will be cast to a string.

8.1.5.2 Event handlers on elements, Document objects, and Window objects

The following are the event handlers (and their corresponding event handler event types) supported by all HTML elements, as both event handler content attributes and event handler IDL attributes; and supported by all Document and Window objects, as event handler IDL attributes:

Event handler Event handler event type
onabort

GlobalEventHandlers/onabort

Support in one engine only.

Firefox?Safari?ChromeYes
Opera?EdgeYes
Edge (Legacy)NoInternet Explorer?
Firefox Android?Safari iOS?Chrome AndroidYesWebView AndroidYesSamsung InternetYesOpera Android?
abort
onauxclick auxclick
oncancel

GlobalEventHandlers/oncancel

Support in one engine only.

FirefoxNoSafari?ChromeYes
Opera?EdgeYes
Edge (Legacy)NoInternet Explorer?
Firefox AndroidNoSafari iOS?Chrome AndroidYesWebView AndroidYesSamsung InternetYesOpera Android?
cancel
oncanplay

GlobalEventHandlers/oncanplay

FirefoxYesSafari?ChromeYes
Opera?EdgeYes
Edge (Legacy)NoInternet Explorer?
Firefox AndroidYesSafari iOS?Chrome AndroidYesWebView AndroidYesSamsung InternetYesOpera Android?
canplay
oncanplaythrough

GlobalEventHandlers/oncanplaythrough

FirefoxYesSafari?ChromeYes
Opera?EdgeYes
Edge (Legacy)NoInternet Explorer?
Firefox AndroidYesSafari iOS?Chrome AndroidYesWebView AndroidYesSamsung InternetYesOpera Android?
canplaythrough
onchange

GlobalEventHandlers/onchange

Support in all current engines.

Firefox1+Safari3+Chrome1+
Opera9+Edge79+
Edge (Legacy)12+Internet Explorer9+
Firefox Android4+Safari iOS1+Chrome Android18+WebView Android1+Samsung Internet1.0+Opera Android10.1+
change
onclick

GlobalEventHandlers/onclick

Support in all current engines.

Firefox1+Safari3+Chrome1+
Opera9+Edge79+
Edge (Legacy)12+Internet Explorer9+
Firefox Android4+Safari iOS1+Chrome Android18+WebView Android1+Samsung Internet1.0+Opera Android10.1+
click
onclose

GlobalEventHandlers/onclose

FirefoxYesSafariNoChromeYes
Opera?EdgeYes
Edge (Legacy)NoInternet Explorer?
Firefox AndroidYesSafari iOSNoChrome AndroidYesWebView AndroidYesSamsung InternetYesOpera Android?
close
oncontextmenu

GlobalEventHandlers/oncontextmenu

FirefoxYesSafari?ChromeYes
Opera?EdgeYes
Edge (Legacy)18Internet Explorer?
Firefox Android?Safari iOS?Chrome AndroidNoWebView AndroidNoSamsung InternetNoOpera Android?
contextmenu
oncuechange

GlobalEventHandlers/oncuechange

Firefox68+Safari?ChromeYes
Opera?EdgeYes
Edge (Legacy)NoInternet Explorer?
Firefox Android68+Safari iOS?Chrome AndroidYesWebView AndroidYesSamsung InternetYesOpera Android?
cuechange
ondblclick

GlobalEventHandlers/ondblclick

FirefoxYesSafari?ChromeYes
Opera?EdgeYes
Edge (Legacy)18Internet Explorer?
Firefox Android?Safari iOS?Chrome AndroidNoWebView AndroidNoSamsung InternetNoOpera Android?
dblclick
ondrag drag
ondragend dragend
ondragenter dragenter
ondragleave dragleave
ondragover dragover
ondragstart dragstart
ondrop drop
ondurationchange

GlobalEventHandlers/ondurationchange

Firefox3.5+Safari?ChromeYes
Opera?EdgeYes
Edge (Legacy)NoInternet Explorer?
Firefox Android4+Safari iOS?Chrome AndroidYesWebView AndroidYesSamsung InternetYesOpera Android?
durationchange
onemptied

GlobalEventHandlers/onemptied

Firefox3.5+Safari?ChromeYes
Opera?EdgeYes
Edge (Legacy)NoInternet Explorer?
Firefox Android4+Safari iOS?Chrome AndroidYesWebView AndroidYesSamsung InternetYesOpera Android?
emptied
onended

GlobalEventHandlers/onended

Firefox3.5+Safari?ChromeYes
Opera?EdgeYes
Edge (Legacy)NoInternet Explorer?
Firefox Android4+Safari iOS?Chrome AndroidYesWebView AndroidYesSamsung InternetYesOpera Android?
ended
onformdata

GlobalEventHandlers/onformdata

Firefox72+SafariNoChrome77+
Opera64+Edge79+
Edge (Legacy)NoInternet ExplorerNo
Firefox AndroidNoSafari iOSNoChrome Android77+WebView Android77+Samsung Internet12.0+Opera Android55+
formdata
oninput input
oninvalid

GlobalEventHandlers/oninvalid

FirefoxYesSafari?ChromeYes
OperaYesEdgeYes
Edge (Legacy)NoInternet Explorer?
Firefox AndroidYesSafari iOS?Chrome AndroidYesWebView AndroidYesSamsung InternetYesOpera AndroidYes
invalid
onkeydown

GlobalEventHandlers/onkeydown

FirefoxYesSafari?ChromeYes
Opera?EdgeYes
Edge (Legacy)18Internet Explorer?
Firefox AndroidYesSafari iOS?Chrome AndroidYesWebView AndroidYesSamsung InternetYesOpera Android?
keydown
onkeypress

GlobalEventHandlers/onkeypress

FirefoxYesSafari?ChromeYes
Opera?EdgeYes
Edge (Legacy)18Internet Explorer?
Firefox AndroidYesSafari iOS?Chrome AndroidYesWebView AndroidYesSamsung InternetYesOpera Android?
keypress
onkeyup

GlobalEventHandlers/onkeyup

FirefoxYesSafari?ChromeYes
Opera?EdgeYes
Edge (Legacy)18Internet Explorer?
Firefox AndroidYesSafari iOS?Chrome AndroidYesWebView AndroidYesSamsung InternetYesOpera Android?
keyup
onloadeddata

GlobalEventHandlers/onloadeddata

Firefox3.5+Safari?ChromeYes
Opera?EdgeYes
Edge (Legacy)NoInternet Explorer?
Firefox Android4+Safari iOS?Chrome AndroidYesWebView AndroidYesSamsung InternetYesOpera Android?
loadeddata
onloadedmetadata

GlobalEventHandlers/onloadedmetadata

Firefox3.5+Safari?ChromeYes
Opera?EdgeYes
Edge (Legacy)NoInternet Explorer?
Firefox Android4+Safari iOS?Chrome AndroidYesWebView AndroidYesSamsung InternetYesOpera Android?
loadedmetadata
onloadstart

GlobalEventHandlers/onloadstart

Support in all current engines.

Firefox52+SafariYesChromeYes
OperaYesEdgeYes
Edge (Legacy)12+Internet ExplorerYes
Firefox Android52+Safari iOSYesChrome AndroidYesWebView AndroidYesSamsung InternetYesOpera AndroidYes
loadstart
onmousedown

GlobalEventHandlers/onmousedown

Support in all current engines.

FirefoxYesSafariYesChromeYes
OperaYesEdgeYes
Edge (Legacy)12+Internet ExplorerYes
Firefox AndroidYesSafari iOSYesChrome AndroidYesWebView AndroidYesSamsung InternetYesOpera AndroidYes
mousedown
onmouseenter

GlobalEventHandlers/onmouseenter

Support in all current engines.

Firefox10+SafariYesChrome30+
Opera17+Edge79+
Edge (Legacy)12+Internet Explorer5.5+
Firefox Android10+Safari iOSYesChrome AndroidYesWebView AndroidYesSamsung InternetYesOpera Android18+
mouseenter
onmouseleave

GlobalEventHandlers/onmouseleave

Support in all current engines.

Firefox10+SafariYesChrome30+
Opera17+Edge79+
Edge (Legacy)12+Internet Explorer5.5+
Firefox Android10+Safari iOSYesChrome AndroidYesWebView AndroidYesSamsung InternetYesOpera Android18+
mouseleave
onmousemove

GlobalEventHandlers/onmousemove

Support in all current engines.

FirefoxYesSafariYesChromeYes
OperaYesEdgeYes
Edge (Legacy)12+Internet ExplorerYes
Firefox AndroidYesSafari iOSYesChrome AndroidYesWebView AndroidYesSamsung InternetYesOpera AndroidYes
mousemove
onmouseout

GlobalEventHandlers/onmouseout

Support in all current engines.

FirefoxYesSafariYesChromeYes
OperaYesEdgeYes
Edge (Legacy)12+Internet ExplorerYes
Firefox AndroidYesSafari iOSYesChrome AndroidYesWebView AndroidYesSamsung InternetYesOpera AndroidYes
mouseout
onmouseover

GlobalEventHandlers/onmouseover

Support in all current engines.

FirefoxYesSafariYesChromeYes
OperaYesEdgeYes
Edge (Legacy)12+Internet ExplorerYes
Firefox AndroidYesSafari iOSYesChrome AndroidYesWebView AndroidYesSamsung InternetYesOpera AndroidYes
mouseover
onmouseup

GlobalEventHandlers/onmouseup

Support in all current engines.

FirefoxYesSafariYesChromeYes
OperaYesEdgeYes
Edge (Legacy)12+Internet ExplorerYes
Firefox AndroidYesSafari iOSYesChrome AndroidYesWebView AndroidYesSamsung InternetYesOpera AndroidYes
mouseup
onpause

GlobalEventHandlers/onpause

Firefox3.5+Safari?ChromeYes
Opera?EdgeYes
Edge (Legacy)NoInternet Explorer?
Firefox Android4+Safari iOS?Chrome AndroidYesWebView AndroidYesSamsung InternetYesOpera Android?
pause
onplay

GlobalEventHandlers/onplay

Firefox3.5+Safari?ChromeYes
Opera?EdgeYes
Edge (Legacy)NoInternet Explorer?
Firefox Android4+Safari iOS?Chrome AndroidYesWebView AndroidYesSamsung InternetYesOpera Android?
play
onplaying playing
onprogress progress
onratechange ratechange
onreset

GlobalEventHandlers/onreset

Support in all current engines.

FirefoxYesSafariYesChromeYes
OperaYesEdgeYes
Edge (Legacy)18Internet Explorer?
Firefox AndroidYesSafari iOSYesChrome AndroidYesWebView AndroidYesSamsung InternetYesOpera AndroidYes
reset
onsecuritypolicyviolation securitypolicyviolation
onseeked seeked
onseeking seeking
onselect

GlobalEventHandlers/onselect

FirefoxYesSafari?ChromeYes
Opera?EdgeYes
Edge (Legacy)18Internet Explorer?
Firefox AndroidYesSafari iOS?Chrome AndroidYesWebView AndroidYesSamsung InternetYesOpera Android?
select
onslotchange slotchange
onstalled stalled
onsubmit

GlobalEventHandlers/onsubmit

Support in all current engines.

FirefoxYesSafariYesChromeYes
OperaYesEdgeYes
Edge (Legacy)12+Internet ExplorerYes
Firefox AndroidYesSafari iOSYesChrome AndroidYesWebView AndroidYesSamsung InternetYesOpera AndroidYes
submit
onsuspend suspend
ontimeupdate timeupdate
ontoggle toggle
onvolumechange volumechange
onwaiting waiting
onwebkitanimationend webkitAnimationEnd
onwebkitanimationiteration webkitAnimationIteration
onwebkitanimationstart webkitAnimationStart
onwebkittransitionend webkitTransitionEnd
onwheel

GlobalEventHandlers/onwheel

Support in all current engines.

FirefoxYesSafariYesChrome61+
Opera48+Edge79+
Edge (Legacy)12+Internet ExplorerYes
Firefox AndroidYesSafari iOSYesChrome Android61+WebView Android61+Samsung Internet8.0+Opera Android45+
wheel

The following are the event handlers (and their corresponding event handler event types) supported by all HTML elements other than body and frameset elements, as both event handler content attributes and event handler IDL attributes; supported by all Document objects, as event handler IDL attributes; and supported by all Window objects, as event handler IDL attributes on the Window objects themselves, and with corresponding event handler content attributes and event handler IDL attributes exposed on all body and frameset elements that are owned by that Window object's associated Document:

Event handler Event handler event type
onblur

GlobalEventHandlers/onblur

Support in all current engines.

FirefoxYesSafariYesChromeYes
OperaYesEdgeYes
Edge (Legacy)12+Internet ExplorerYes
Firefox AndroidYesSafari iOSYesChrome AndroidYesWebView AndroidYesSamsung InternetYesOpera AndroidYes
blur
onerror

GlobalEventHandlers/onerror

Support in all current engines.

Firefox1+Safari6+Chrome10+
Opera11.6+Edge79+
Edge (Legacy)12+Internet Explorer9+
Firefox Android4+Safari iOS6+Chrome Android18+WebView Android37+Samsung Internet1.0+Opera Android12+

HTMLMediaElement/onerror

Support in all current engines.

Firefox3.5+SafariYesChromeYes
OperaYesEdgeYes
Edge (Legacy)12+Internet Explorer9+
Firefox AndroidYesSafari iOSYesChrome AndroidYesWebView AndroidYesSamsung InternetYesOpera AndroidYes
error
onfocus

GlobalEventHandlers/onfocus

Support in all current engines.

FirefoxYesSafariYesChromeYes
OperaYesEdgeYes
Edge (Legacy)12+Internet ExplorerYes
Firefox AndroidYesSafari iOSYesChrome AndroidYesWebView AndroidYesSamsung InternetYesOpera AndroidYes
focus
onload

GlobalEventHandlers/onload

Support in all current engines.

Firefox1+Safari3+Chrome1+
Opera9+Edge79+
Edge (Legacy)12+Internet Explorer9+
Firefox Android4+Safari iOS1+Chrome Android18+WebView Android1+Samsung Internet1.0+Opera Android10.1+
load
onresize

GlobalEventHandlers/onresize

Support in all current engines.

FirefoxYesSafariYesChrome45+
Opera32+Edge79+
Edge (Legacy)12+Internet ExplorerYes
Firefox AndroidYesSafari iOSYesChrome Android45+WebView Android45+Samsung Internet5.0+Opera Android32+
resize
onscroll

GlobalEventHandlers/onscroll

FirefoxYesSafari?ChromeYes
Opera?EdgeYes
Edge (Legacy)18Internet Explorer?
Firefox AndroidYesSafari iOS?Chrome AndroidYesWebView AndroidYesSamsung InternetYesOpera Android?
scroll

We call the set of the names of the event handlers listed in the first column of this table the Window-reflecting body element event handler set.


The following are the event handlers (and their corresponding event handler event types) supported by Window objects, as event handler IDL attributes on the Window objects themselves, and with corresponding event handler content attributes and event handler IDL attributes exposed on all body and frameset elements that are owned by that Window object's associated Document:

Event handler Event handler event type
onafterprint

WindowEventHandlers/onafterprint

Support in all current engines.

Firefox6+Safari13+Chrome63+
Opera50+Edge79+
Edge (Legacy)12+Internet ExplorerYes
Firefox Android?Safari iOS13+Chrome Android63+WebView Android63+Samsung Internet8.0+Opera Android46+
afterprint
onbeforeprint

WindowEventHandlers/onbeforeprint

Support in all current engines.

Firefox6+Safari13+Chrome63+
Opera50+Edge79+
Edge (Legacy)12+Internet ExplorerYes
Firefox Android?Safari iOS13+Chrome Android63+WebView Android63+Samsung Internet8.0+Opera Android46+
beforeprint
onbeforeunload

WindowEventHandlers/onbeforeunload

Support in all current engines.

Firefox1+Safari3+Chrome1+
Opera12+Edge79+
Edge (Legacy)12+Internet Explorer4+
Firefox Android4+Safari iOS1+Chrome Android18+WebView Android1+Samsung Internet1.0+Opera Android12+
beforeunload
onhashchange

WindowEventHandlers/onhashchange

Support in all current engines.

Firefox3.6+Safari5+Chrome5+
Opera10+Edge79+
Edge (Legacy)12+Internet Explorer8+
Firefox Android4+Safari iOS5+Chrome Android18+WebView Android37+Samsung Internet1.0+Opera Android10.1+
hashchange
onlanguagechange

WindowEventHandlers/onlanguagechange

Firefox32+Safari?Chrome37+
Opera24+Edge79+
Edge (Legacy)NoInternet ExplorerNo
Firefox Android4+Safari iOS?Chrome Android37+WebView Android37+Samsung Internet4.0+Opera Android24+
languagechange
onmessage

WindowEventHandlers/onmessage

Support in one engine only.

Firefox?Safari?Chrome60+
Opera47+Edge79+
Edge (Legacy)NoInternet Explorer?
Firefox Android?Safari iOS?Chrome Android60+WebView Android60+Samsung Internet8.0+Opera Android44+
message
onmessageerror

WindowEventHandlers/onmessageerror

Firefox57+Safari?Chrome60+
Opera47+Edge79+
Edge (Legacy)NoInternet Explorer?
Firefox Android57+Safari iOS?Chrome Android60+WebView Android60+Samsung Internet8.0+Opera Android44+
messageerror
onoffline offline
ononline online
onpagehide pagehide
onpageshow pageshow
onpopstate

WindowEventHandlers/onpopstate

Support in all current engines.

Firefox4+Safari6+Chrome5+
Opera11.5+Edge79+
Edge (Legacy)12+Internet Explorer10+
Firefox Android4+Safari iOS5.1+Chrome Android18+WebView Android37+Samsung Internet1.0+Opera Android11.5+
popstate
onrejectionhandled

WindowEventHandlers/onrejectionhandled

Support in all current engines.

Firefox69+Safari11+Chrome49+
Opera36+Edge79+
Edge (Legacy)NoInternet ExplorerNo
Firefox Android🔰 68+Safari iOS11.3+Chrome Android49+WebView Android49+Samsung Internet5.0+Opera AndroidNo
rejectionhandled
onstorage

WindowEventHandlers/onstorage

Firefox45+Safari?Chrome1+
Opera15+Edge79+
Edge (Legacy)18Internet Explorer?
Firefox Android45+Safari iOS?Chrome Android18+WebView Android37+Samsung Internet1.0+Opera Android14+
storage
onunhandledrejection

WindowEventHandlers/onunhandledrejection

Support in all current engines.

Firefox69+Safari11+Chrome49+
Opera36+Edge79+
Edge (Legacy)NoInternet ExplorerNo
Firefox Android🔰 68+Safari iOS11.3+Chrome Android49+WebView Android49+Samsung Internet5.0+Opera AndroidNo
unhandledrejection
onunload

WindowEventHandlers/onunload

Support in all current engines.

FirefoxYesSafariYesChromeYes
OperaYesEdgeYes
Edge (Legacy)12+Internet ExplorerYes
Firefox AndroidYesSafari iOSYesChrome AndroidYesWebView AndroidYesSamsung InternetYesOpera AndroidYes
unload

The following are the event handlers (and their corresponding event handler event types) supported by all HTML elements, as both event handler content attributes and event handler IDL attributes; and supported by all Document objects, as event handler IDL attributes:

Event handler Event handler event type
oncut cut
oncopy copy
onpaste paste

The following are the event handlers (and their corresponding event handler event types) supported on Document objects as event handler IDL attributes:

Event handler Event handler event type
onreadystatechange readystatechange

8.2 The WindowOrWorkerGlobalScope mixin

WindowOrWorkerGlobalScope

Support in all current engines.

Firefox1+SafariYesChrome4+
OperaYesEdge79+
Edge (Legacy)12+Internet ExplorerYes
Firefox Android4+Safari iOSYesChrome Android18+WebView AndroidYesSamsung Internet1.0+Opera AndroidYes

The WindowOrWorkerGlobalScope mixin is for use of APIs that are to be exposed on Window and WorkerGlobalScope objects.

Other standards are encouraged to further extend it using partial interface mixin WindowOrWorkerGlobalScope { … }; along with an appropriate reference.

self . isSecureContext

Returns whether or not this global object represents a secure context. [SECURE-CONTEXTS]

self . origin

WindowOrWorkerGlobalScope/origin

Support in all current engines.

Firefox54+Safari11+Chrome59+
OperaNoEdge79+
Edge (Legacy)NoInternet ExplorerNo
Firefox Android54+Safari iOS11+Chrome Android59+WebView Android59+Samsung Internet7.0+Opera AndroidNo

Returns the global object's origin, serialized as string.

self . crossOriginIsolated

WindowOrWorkerGlobalScope/crossOriginIsolated

Support in one engine only.

Firefox72+SafariNoChromeNo
OperaNoEdgeNo
Edge (Legacy)NoInternet ExplorerNo
Firefox AndroidNoSafari iOSNoChrome AndroidNoWebView AndroidNoSamsung InternetNoOpera AndroidNo

Returns whether scripts running in this global are allowed to use APIs that require cross-origin isolation. This depends on the `Cross-Origin-Opener-Policy` and `Cross-Origin-Embedder-Policy` HTTP response headers and the "cross-origin-isolated" feature.

Developers are strongly encouraged to use self.origin over location.origin. The former returns the origin of the environment, the latter of the URL of the environment. Imagine the following script executing in a document on https://stargate.example/:

var frame = document.createElement("iframe")
frame.onload = function() {
  var frameWin = frame.contentWindow
  console.log(frameWin.location.origin) // "null"
  console.log(frameWin.origin) // "https://stargate.example"
}
document.body.appendChild(frame)

self.origin is a more reliable security indicator.

8.3 Base64 utility methods

WindowOrWorkerGlobalScope/atob

Support in all current engines.

Firefox1+Safari3+Chrome4+
Opera10.5+Edge79+
Edge (Legacy)12+Internet Explorer10+
Firefox Android4+Safari iOS1+Chrome Android18+WebView Android37+Samsung Internet1.0+Opera Android11+
caniuse.com table

The atob() and btoa() methods allow developers to transform content to and from the base64 encoding.

In these APIs, for mnemonic purposes, the "b" can be considered to stand for "binary", and the "a" for "ASCII". In practice, though, for primarily historical reasons, both the input and output of these functions are Unicode strings.

result = self . btoa( data )

WindowOrWorkerGlobalScope/btoa

Support in all current engines.

Firefox1+Safari3+Chrome4+
Opera10.5+Edge79+
Edge (Legacy)12+Internet Explorer10+
Firefox Android4+Safari iOS1+Chrome Android18+WebView Android37+Samsung Internet1.0+Opera Android11+

Takes the input data, in the form of a Unicode string containing only characters in the range U+0000 to U+00FF, each representing a binary byte with values 0x00 to 0xFF respectively, and converts it to its base64 representation, which it returns.

Throws an "InvalidCharacterError" DOMException exception if the input string contains any out-of-range characters.

result = self . atob( data )

WindowOrWorkerGlobalScope/atob

Support in all current engines.

Firefox1+Safari3+Chrome4+
Opera10.5+Edge79+
Edge (Legacy)12+Internet Explorer10+
Firefox Android4+Safari iOS1+Chrome Android18+WebView Android37+Samsung Internet1.0+Opera Android11+

Takes the input data, in the form of a Unicode string containing base64-encoded binary data, decodes it, and returns a string consisting of characters in the range U+0000 to U+00FF, each representing a binary byte with values 0x00 to 0xFF respectively, corresponding to that binary data.

Throws an "InvalidCharacterError" DOMException if the input string is not valid base64 data.