Event reference

事件為一些有趣事情,發生後會被傳出以通知 code。每個事件被表示為一個根據 Event 所定義的物件,且可能會有額外自訂欄位與(或)函式來描述發生了什麼事。事件可以表示從使用者互動到自動通知等渲染 model 所有的事情。

This article offers a list of events that can be sent; some are standard events defined in official specifications, while others are events used internally by specific browsers; for example, Mozilla-specific events are listed so that add-ons can use them to interact with the browser.no

事件索引

事件類型 描述 文件
Animation

Events related to the Web Animation API (en-US).

Used to respond to changes in animation status (e.g. when an animation starts or ends).

Animation events fired on Document (en-US), Window (en-US), HTMLElement (en-US).
Asynchronous data fetching

Events related to the fetching data.

Events fired on AbortSignal (en-US), XMLHttpRequest, FileReader.
Clipboard

Events related to the Clipboard API (en-US).

Used to notify when content is cut, copied, or pasted.

Events fired on Document (en-US), Element (en-US), Window (en-US).
Composition

Events related to composition; entering text "indirectly" (rather than using normal keyboard presses).

For example, text entered via a speech to text engine, or using special key combinations that modify keyboard presses to represent new characters in another language.

Events fired on Element (en-US).
CSS transition

Events related to CSS Transitions (en-US).

Provides notification events when CSS transitions start, stop, are cancelled, etc.

Events fired on Document (en-US), HTMLElement (en-US), Window (en-US).
Database

Events related to database operations: opening, closing, transactions, errors, etc.

Events fired on IDBDatabase (en-US), IDBOpenDBRequest (en-US), IDBRequest (en-US), IDBTransaction (en-US).
DOM mutation

Events related to modifications to the Document Object Model (DOM) hierarchy and nodes.

Warning: Mutation Events (en-US) are deprecated. Mutation Observers should be used instead.

Drag'n'drop, Wheel

Events related to using the HTML Drag and Drop API and wheel events.

Drag and Wheel events are derived from mouse events. While they are fired when using mouse wheel or drag/drop, they may also be used with other appropriate hardware.

Drag events fired on Document (en-US)

Wheel events fired on Document (en-US) and Element (en-US)

Focus

Events related to elements gaining and losing focus.

Events fired on Element (en-US), Window (en-US).
Form

Events related to forms being constructed, reset and submitted.

Events fired on HTMLFormElement (en-US).
Fullscreen

Events related to the Fullscreen API.

Used to notify when the transitioning between full screen and windowed modes, and also of errors occurring during this transition.

Events fired on Document (en-US), Element (en-US).
Gamepad

Events related to the Gamepad API (en-US).

Events fired on Window (en-US).
Gestures

Touch events are recommended for implementing gestures.

Events fired on Document (en-US), Element (en-US).

In addition there are a number of non-standard gesture events:

History

Events related to the History API.

Events fired on Window (en-US).
HTML element content display management

Events related to changing the state of a display or textual element.

Events fired on HTMLDetailsElement (en-US), HTMLDialogElement (en-US), HTMLSlotElement (en-US).
Inputs

Events related to HTML input elements e.g. <input> (en-US), <select> (en-US), or <textarea> (en-US).

Events fired on HTMLElement (en-US), HTMLInputElement (en-US).
Keyboard

Events related to using a keyboard.

Used to notify when keys are moved up, down, or just pressed.

Events fired on Document (en-US), Element (en-US).
Loading/unloading documents

Events related to loading and unloading documents.

Events fired on Document (en-US) and Window (en-US).

Manifests

Events related to installation of progressive web app manifests.

Events fired on Window (en-US).
Media

Events related to media usage (including the Media Capture and Streams API, Web Audio API, Picture-in-Picture API (en-US), etc.).

Events fired on ScriptProcessorNode (en-US), HTMLMediaElement (en-US), AudioTrackList (en-US), AudioScheduledSourceNode (en-US), MediaRecorder (en-US), MediaStream (en-US), MediaStreamTrack (en-US), VideoTrackList (en-US), HTMLTrackElement (en-US), OfflineAudioContext (en-US), TextTrack (en-US), TextTrackList (en-US), Element/audio, Element/video (en-US).
Messaging

Events related to a window receiving a message from another browsing context.

Events fired on Window (en-US).
Mouse

Events related to using a computer mouse (en-US).

Used to notify when the mouse is clicked, doubleclicked, up and down events, right-click, movement in and out of an element, text selection, etc.

Pointer events provide a hardware-agnostic alternative to mouse events. Drag and Wheel events are derived from mouse events.

Mouse events fired on Element (en-US)
Network/Connection

Events related to gaining and losing network connection.

Events fired on Window (en-US).

Events fired on NetworkInformation (en-US) (Network Information API).

Payments

Events related to the Payment Request API.

Events fired on PaymentRequest, PaymentResponse (en-US).

Performance

Events related to High Resolution Time API (en-US), Performance Timeline API, Navigation Timing API (en-US), User Timing API (en-US), and Resource Timing API (en-US).

Events fired on Performance (en-US).

Pointer

Events related to the Pointer Events API (en-US).

Provides hardware-agnostic notification from pointing devices including Mouse, Touch, pen/stylus.

Events fired on Document (en-US), HTMLElement (en-US).
Print

Events related to printing.

Events fired on Window (en-US).
Promise rejection

Events sent to the global script context when any JavaScript promise is rejected.

Events fired on Window (en-US).
Sockets

Events related to the WebSockets API.

Events fired on Websocket.
SVG

Events related to SVG images.

Events fired on SVGElement (en-US), SVGAnimationElement (en-US), SVGGraphicsElement (en-US).

Text selection

Selection API (en-US) events related to selecting text.

Event (selectionchange) fired on HTMLTextAreaElement (en-US), HTMLInputElement (en-US).

Touch

Events related to the Touch Events API.

Provides notification events from interacting with a touch sensitive screen (i.e. using a finger or stylus). Not related to the Force Touch API (en-US).

Events fired on Document (en-US), Element (en-US).
Virtual reality

Events related to the WebXR Device API (en-US).

Warning: The WebVR API (en-US) (and associated Window events (en-US)) are deprecated.

Events fired on XRSystem (en-US), XRSession (en-US), XRReferenceSpace (en-US).
RTC (real time communication)

Events related to the WebRTC API (en-US).

Events fired on RTCDataChannel (en-US), RTCDTMFSender (en-US), RTCIceTransport (en-US), RTCPeerConnection (en-US).
Server-sent events

Events related to the server sent events API.

Events fired on EventSource (en-US).
Speech

Events related to the Web Speech API (en-US).

Events fired on SpeechSynthesisUtterance (en-US).
Workers

Events related to the Web Workers API (en-US), Service Worker API (en-US), Broadcast Channel API (en-US), and Channel Messaging API.

Used to respond to new messages and message sending errors. Service workers can also be notified of other events, including push notifications, users clicking on displayed notifications, that push subscription has been invalidated, deletion of items from the content index, etc.

Events fired on ServiceWorkerGlobalScope (en-US), DedicatedWorkerGlobalScope (en-US), SharedWorkerGlobalScope (en-US), WorkerGlobalScope (en-US), Worker (en-US), WorkerGlobalScope (en-US), BroadcastChannel (en-US), MessagePort (en-US).

事件分類

規範

Specification
HTML Standard
# events-2