1. 程式人生 > >瀏覽器事件總結

瀏覽器事件總結

原文來源於MDN,有時候MDN無法訪問,可以自己參考下面的說明。

DOM 事件被髮送用於通知程式碼相關的事情已經發生了。每個事件都是繼承自Event 類的物件,可以包括自定義的成員屬性及函式用於獲取事件發生時相關的更多資訊。事件可以表示從基本使用者互動到渲染模型中發生的事件的自動通知的所有內容。

本文提供了一個可以傳送的事件的列表;一些是官方標準中的標準事件,另一些則是在特定瀏覽器內部使用的事件;例如,Mozilla 列出的特定事件使 拓展 可以用它們與瀏覽器互動。

最常見的類別

事件名稱 何時觸發
cached
manifest中列出的資源已經下載,應用程式現在已快取。
error 資源載入失敗時
abort 正在載入資源已經被中止時
load 資源及其相關資源已完成載入。
beforeunload window,document 及其資源即將被解除安裝。
unload 文件或一個依賴資源正在被解除安裝。

網路事件

事件名稱 何時觸發
online
瀏覽器已獲得網路訪問。
offline 瀏覽器已失去網路訪問。
事件名稱 何時觸發
focus 元素獲得焦點(不會冒泡)
blur 元素失去焦點(不會冒泡)

Websocket事件

事件名稱 何時觸發
open WebSocket連線已建立
message 通過WebSocket接收到一條訊息
error WebSocket連線異常被關閉(比如有些資料無法傳送)。
close WebSocket連線已關閉
事件名稱 何時觸發
pagehide A session history entry is being traversed from.
pageshow A session history entry is being traversed to.
popstate A session history entry is being navigated to (in certain cases).
事件觸發 何時觸發
animationstart 某個CSS動畫開始時觸發
animationend 某個CSS動畫完成時觸發
animationiteration 某個CSS動畫完成後重新開始時觸發
事件名稱 何時觸發
reset 點選重置按鈕時
submit 點選提交按鈕
時間名稱 何時觸發
beforeprint 印表機已經就緒時觸發
afterprint 印表機關閉時觸發
Event Name Fired When
compositionstart The composition of a passage of text is prepared (similar to keydown for a keyboard input, but works with other inputs such as speech recognition).
compositionupdate A character is added to a passage of text being composed.
compositionend The composition of a passage of text has been completed or canceled.
Event Name Fired When
fullscreenchange An element was turned to fullscreen mode or back to normal mode.
fullscreenerror It was impossible to switch to fullscreen mode for technical reasons or because the permission was denied.
resize The document view has been resized.
scroll The document view or an element has been scrolled.
Event Name Fired When
cut 已經剪貼選中的文字內容並且複製到了剪貼簿
copy 已經把選中的文字內容複製到了剪貼簿
paste 從剪貼簿複製的文字內容被貼上
Event Name Fired When
keydown 按下任意按鍵
keypress 除 Shift, Fn, CapsLock 外任意鍵被按住. (連續觸發)
keyup 釋放任意按鍵
Event Name Fired When
mouseenter 指標移到有事件監聽的元素內
mouseover 指標移到有事件監聽的元素或者它的子元素內
mousemove 指標在元素內移動時持續觸發
mousedown 在元素上按下任意滑鼠按鈕
mouseup 在元素上釋放任意滑鼠按鍵
click 在元素上按下並釋放任意滑鼠按鍵
dblclick 在元素上雙擊滑鼠按鈕
contextmenu 右鍵點選 (右鍵選單顯示前).
wheel 滾輪向任意方向滾動
mouseleave 指標移出元素範圍外(不冒泡)
mouseout 指標移出元素,或者移到它的子元素上
select 文字被選中被選中
pointerlockchange 滑鼠被鎖定或者解除鎖定發生時
pointerlockerror 可能因為一些技術的原因滑鼠鎖定被禁止時。
Event Name Fired When
dragstart 使用者開始拖動HTML元素或選中的文字
drag 正在拖動元素或文字選區(在此過程中持續觸發,每350ms觸發一次)
dragend 拖放操作結束 (鬆開滑鼠按鈕或按下Esc鍵)
dragenter 被拖動的元素或文字選區移入有效釋放目標區
dragover 被拖動的元素或文字選區正在有效釋放目標上被拖動 (在此過程中持續觸發,每350ms觸發一次)
dragleave 被拖動的元素或文字選區移出有效釋放目標區
drop 元素在有效釋放目標區上釋放
Event Name Fired When
durationchange The duration attribute has been updated.
loadedmetadata The metadata has been loaded.
loadeddata The first frame of the media has finished loading.
canplay The browser can play the media, but estimates that not enough data has been loaded to play the media up to its end without having to stop for further buffering of content.
canplaythrough The browser estimates it can play the media up to its end without stopping for content buffering.
ended Playback has stopped because the end of the media was reached.
emptied The media has become empty; for example, this event is sent if the media has already been loaded (or partially loaded), and the load()method is called to reload it.
stalled The user agent is trying to fetch media data, but data is unexpectedly not forthcoming.
suspend Media data loading has been suspended.
play Playback has begun.
playing Playback is ready to start after having been paused or delayed due to lack of data.
pause Playback has been paused.
waiting Playback has stopped because of a temporary lack of data.
seeking A seek operation began.
seeked A seek operation completed.
ratechange The playback rate has changed.
timeupdate The time indicated by the currentTime attribute has been updated.
volumechange The volume has changed.
complete The rendering of an OfflineAudioContext is terminated.
ended Playback has stopped because the end of the media was reached.
audioprocess The input buffer of a ScriptProcessorNode is ready to be processed.
Event Name Fired When
loadstart Progress has begun.
progress In progress.
error Progression has failed.
timeout Progression is terminated due to preset time expiring.
abort Progression has been terminated (not due to an error).
load Progression has been successful.
loadend Progress has stopped (after "error", "abort" or "load" have been dispatched).

儲存事件

change (see Non-standard events)storage

更新事件

checkingdownloadingerrornoupdateobsoleteupdateready

值變化事件

broadcastCheckboxStateChangehashchangeinputRadioStateChangereadystatechangeValueChange

未分類的事件

invalidlocalizedmessagemessagemessageopenshow

不常見 和 非標準分類

SVG事件

SVGAbortSVGErrorSVGLoadSVGResizeSVGScrollSVGUnloadSVGZoom

資料庫事件

abortblockedcompleteerror(link)successupgradeneededversionchange

通知事件

AlertActiveAlertClose

CSS事件

CssRuleViewRefreshedCssRuleViewChangedCssRuleViewCSSLinkClickedtransitionend

指令碼事件

afterscriptexecutebeforescriptexecute

選單事件

DOMMenuItemActiveDOMMenuItemInactive

視窗事件

DOMWindowCreatedDOMTitleChangedDOMWindowCloseSSWindowClosingSSWindowStateReadySSWindowStateBusyclose

文件事件

DOMLinkAddedDOMLinkRemovedDOMMetaAddedDOMMetaRemovedDOMWillOpenModalDialogDOMModalDialogClosed

彈出事件

popuphiddenpopuphidingpopupshowingpopupshownDOMPopupBlocked

Tab事件

TabOpenTabCloseTabSelectTabShowTabHideTabPinnedTabUnpinnedSSTabClosingSSTabRestoringSSTabRestoredvisibilitychange

電池事件

chargingchangechargingtimechangedischargingtimechangelevelchange

呼叫事件

alertingbusycallschangedcfstatechangeconnectedconnectingdialingdisconnecteddisconnectingerrorheld, holdingincomingresumingstatechangevoicechange

感測器事件

compassneedscalibrationdevicelightdevicemotiondeviceorientationdeviceproximityMozOrientationorientationchangeuserproximity

智慧卡事件

icccardlockerroriccinfochangesmartcard-insertsmartcard-removestkcommandstksessionendcardstatechange

簡訊和USSD事件

deliveredreceivedsentussdreceived

幀事件

mozbrowserclosemozbrowsercontextmenumozbrowsererrormozbrowsericonchangemozbrowserlocationchangemozbrowserloadendmozbrowserloadstartmozbrowseropenwindowmozbrowsersecuritychangemozbrowsershowmodalprompt(link)mozbrowsertitlechangeDOMFrameContentLoaded

DOM變異事件

DOMAttributeNameChangedDOMAttrModifiedDOMCharacterDataModifiedDOMContentLoadedDOMElementNameChangedDOMNodeInsertedDOMNodeInsertedIntoDocumentDOMNodeRemovedDOMNodeRemovedFromDocumentDOMSubtreeModified

觸控事件

MozEdgeUIGestureMozMagnifyGestureMozMagnifyGestureStartMozMagnifyGestureUpdateMozPressTapGestureMozRotateGestureMozRotateGestureStartMozRotateGestureUpdateMozSwipeGestureMozTapGestureMozTouchDownMozTouchMoveMozTouchUptouchcanceltouchendtouchentertouchleavetouchmovetouchstart

指標事件

pointeroverpointerenterpointerdownpointermovepointeruppointercancelpointeroutpointerleavegotpointercapturelostpointercapture

標準事件

這些事件在官方Web規範中定義,並且應在各個瀏覽器中通用。 每個事件都和代表事件接收方的物件(由此您可以查到每個事件提供的資料),定義這個事件的標準或標準連結會一起列出。

事件名稱 事件型別 規範 觸發時機...
abort UIEvent DOM L3 資源載入已被中止
abort ProgressEvent ProgressandXMLHttpRequest Progress被終止(不是error造成的)
abort Event IndexedDB 事務已被中止
afterprint Event HTML5 相關文件已開始列印或列印預覽已被關閉
animationend AnimationEvent CSS Animations 完成一個CSS 動畫
animationiteration AnimationEvent CSS Animations 重複播放一個CSS 動畫
animationstart AnimationEvent CSS Animations 一個CSS 動畫已開始
audioprocess AudioProcessingEvent Web Audio API audioprocess 一個ScriptProcessorNode的輸入緩衝區可處理
audioend Event Web Speech API 使用者代理捕捉到用以語音識別的音訊
audiostart Event Web Speech API 使用者代理開始捕捉用以語音識別的音訊
beforeprint Event HTML5 相關文件將要開始列印或準備列印預覽
beforeunload BeforeUnloadEvent HTML5 即將解除安裝 window,document 及其資源
beginEvent TimeEvent SVG ASMILanimation element begins.
blocked_indexedDB IDBVersionChangeEvent IndexedDB An open connection to a database is blocking aversionchangetransaction on the same database.
blur FocusEvent DOM L3 元素失去焦點 (不會冒泡).
boundary SpeechSynthesisEvent SpeechSynthesisEvent  
cached Event Offline The resources listed in the manifest have been downloaded, and the application is now cached.
canplay Event HTML5 media The user agent can play the media, but estimates that not enough data has been loaded to play the media up to its end without having to stop for further buffering of content.
canplaythrough Event HTML5 media The user agent can play the media, and estimates that enough data has been loaded to play the media up to its end without having to stop for further buffering of content.
change Event DOM L2,HTML5 An element loses focus and its value changed since gaining focus.
chargingchange Event Battery status The battery begins or stops charging.
chargingtimechange Event Battery status ThechargingTimeattribute has been updated.
checking Event Offline The user agent is checking for an update, or attempting to download the cache manifest for the first time.
click MouseEvent DOM L3 A pointing device button has been pressed and released on an element.
close Event WebSocket A WebSocket connection has been closed.
complete   IndexedDB  
complete OfflineAudioCompletionEvent Web Audio API OfflineAudioCompletionEvent The rendering of an OfflineAudioContext is terminated.
compositionend CompositionEvent DOM L3 The composition of a passage of text has been completed or canceled.
compositionstart CompositionEvent DOM L3 The composition of a passage of text is prepared (similar to keydown for a keyboard input, but works with other inputs such as speech recognition).
compositionupdate CompositionEvent DOM L3 A character is added to a passage of text being composed.
contextmenu MouseEvent HTML5 The right button of the mouse is clicked (before the context menu is displayed).
copy ClipboardEvent Clipboard The text selection has been added to the clipboard.
cut ClipboardEvent Clipboard The text selection has been removed from the document and added to the clipboard.
dblclick MouseEvent DOM L3 A pointing device button is clicked twice on an element.
devicelight DeviceLightEvent Ambient Light Events Fresh data is available from a light sensor.
devicemotion DeviceMotionEvent Device Orientation Events Fresh data is available from a motion sensor.
deviceorientation DeviceOrientationEvent Device Orientation Events Fresh data is available from an orientation sensor.
deviceproximity DeviceProximityEvent Proximity Events Fresh data is available from a proximity sensor (indicates an approximated distance between the device and a nearby object).
dischargingtimechange Event Battery status ThedischargingTimeattribute has been updated.
DOMActivate UIEvent DOM L3 A button, link or state changing element is activated (use clickinstead).
DOMAttributeNameChanged MutationNameEvent DOM L3Removed The name of an attribute changed (usemutation observersinstead).
DOMAttrModified MutationEvent DOM L3 The value of an attribute has been modified (usemutation observersinstead).
DOMCharacterDataModified MutationEvent DOM L3 A text or anotherCharacterDatahas changed (usemutation observersinstead).
DOMContentLoaded Event HTML5 The document has finished loading (but not its dependent resources).
DOMElementNameChanged MutationNameEvent DOM L3Removed The name of an element changed (usemutation observersinstead).
DOMFocusIn FocusEvent DOM L3 An element has received focus (use focus or focusininstead).
DOMFocusOut FocusEvent DOM L3 An element has lost focus (use blur or focusout instead).
DOMNodeInserted MutationEvent DOM L3 A node has been added as a child of another node (usemutation observersinstead).
DOMNodeInsertedIntoDocument MutationEvent DOM L3 A node has been inserted into the document (usemutation observersinstead).
DOMNodeRemoved MutationEvent DOM L3 A node has been removed from its parent node (usemutation observersinstead).
DOMNodeRemovedFromDocument MutationEvent DOM L3 A node has been removed from the document (usemutation observersinstead).
DOMSubtreeModified MutationEvent DOM L3 A change happened in the document (usemutation observersinstead).
downloading Event Offline The user agent has found an update and is fetching it, or is downloading the resources listed by the cache manifest for the first time.
drag DragEvent HTML5 An element or text selection is being dragged (every 350ms).
dragend DragEvent HTML5 A drag operation is being ended (by releasing a mouse button or hitting the escape key).
dragenter DragEvent HTML5 A dragged element or text selection enters a valid drop target.
dragleave DragEvent HTML5 A dragged element or text selection leaves a valid drop target.
dragover DragEvent HTML5 An element or text selection is being dragged over a valid drop target (every 350ms).
dragstart DragEvent HTML5 The user starts dragging an element or text selection.
drop DragEvent HTML5 An element is dropped on a valid drop target.
durationchange Event HTML5 media Thedurationattribute has been updated.
emptied Event HTML5 media The media has become empty; for example, this event is sent if the media has already been loaded (or partially loaded), and theload()method is called to reload it.
ended Event HTML5 media Playback has stopped because the end of the media was reached.
ended Event Web Audio API  
endEvent TimeEvent SVG ASMILanimation element ends.
error UIEvent DOM L3 A resource failed to load.
error ProgressEvent ProgressandXMLHttpRequest Progression has failed.
error Event Offline An error occurred while downloading the cache manifest or updating the content of the application.
error Event WebSocket A WebSocket connection has been closed with prejudice (some data couldn't be sent for example).
error Event Server Sent Events An event source connection has been failed.
error Event IndexedDB A request caused an error and failed.
focus FocusEvent DOM L3 An element has received focus (does not bubble).
focusin FocusEvent DOM L3 An element is about to receive focus (bubbles).
focusout FocusEvent DOM L3 An element is about to lose focus (bubbles).
fullscreenchange Event Full Screen An element was turned to fullscreen mode or back to normal mode.
fullscreenerror Event Full Screen It was impossible to switch to fullscreen mode for technical reasons or because the permission was denied.
gamepadconnected GamepadEvent Gamepad A gamepad has been connected.
gamepaddisconnected GamepadEvent Gamepad A gamepad has been disconnected.
hashchange HashChangeEvent HTML5 The fragment identifier of the URL has changed (the part of the URL after the #).
lostpointercapture PointerEvent Pointer Events  
input Event HTML5 The value of an element changes or the content of an element with the attributecontenteditableis modified.
invalid Event HTML5 A submittable element has been checked and doesn't satisfy its constraints.
keydown KeyboardEvent DOM L3 A key is pressed down.
keypress KeyboardEvent DOM L3 A key is pressed down and that key normally produces a character value (use input instead).
keyup KeyboardEvent DOM L3 A key is released.
languagechange Event    
levelchange Event Battery status Thelevelattribute has been updated.
load UIEvent DOM L3 A resource and its dependent resources have finished loading.
load ProgressEvent ProgressandXMLHttpRequest Progression has been successful.
loadeddata Event HTML5 media The first frame of the media has finished loading.
loadedmetadata Event HTML5 media The metadata has been loaded.
loadend ProgressEvent ProgressandXMLHttpRequest Progress has stopped (after "error", "abort" or "load" have been dispatched).
loadstart ProgressEvent ProgressandXMLHttpRequest Progress has begun.
mark SpeechSynthesisEvent Web Speech API  
message MessageEvent WebSocket A message is received through a WebSocket.
message MessageEvent Web Workers A message is received from a Web Worker.
message MessageEvent Web Messaging A message is received from a child (i)frame or a parent window.
message MessageEvent

相關推薦

瀏覽器事件總結

原文來源於MDN,有時候MDN無法訪問,可以自己參考下面的說明。 DOM 事件被髮送用於通知程式碼相關的事情已經發生了。每個事件都是繼承自Event 類的物件,可以包括自定義的成員屬性及函式用於獲取事件發生時相關的更多資訊。事件可以表示從基本使用者互動到渲染模型中發生的事件的自動通知的所有內容。

JavaScript學習——JS事件總結

單擊 png 鼠標移動 方式 比較 chang 使用 購物網站 bmi 回顧之前已經使用過的事件 (onsubmit、onclick、onload、onfocus、onblur、onmouseover、onmouseout) onfocus/onblur:聚焦離焦事件,用

jQuery事件總結

子元素 有一個 trigger tro 禁止 通過 say handle 發生 jQuery提供了兩個方法一個是click方法用於監聽用戶單擊操作,另一個方法是dbclick方法用於監聽用戶雙擊操作。 click事件觸發需要以下幾點: click事件其實是由mousedow

第78天:jQuery事件總結(一)

操作 現在 see 100萬 新的 cli 文檔 dom 擴展 jQuery事件總結(一)   現在就一點一點積累自己的知識體系,記錄自己學到的和自己所理解的jQuery。   JavaScript和HTML之間的交互式通過用戶和瀏覽器操作頁面時引發的事件機制來處理的

第79天:jQuery事件總結(二)

ide 是什麽 導致 另一個 prevent 移除 prop fun 限制 上一篇講到jQuery中的事件,深入學習了加載DOM和事件綁定的相關知識,這篇主要深入討論jQuery事件中的合成事件、事件冒泡和事件移除等內容。   一、合成事件   jQuery有

touch事件總結

總結 [0 chm spa prevent cnblogs touch clas right $("body").on("touchstart", function(e) { e.preventDefault(); startX = e.origina

禁止瀏覽器事件 (圖片拖動)

實例 text cts select cut gin ondrag lec left 禁止右鍵 oncontextmenu="return false" 禁止復制和剪切: oncopy="return false;" oncut="return false;" 禁

js 常用事件總結

pre style 不支持 con class 隨著 hist PE 手機 無論web端還是手機端,用戶的交互總伴隨著事件監聽 下面是我總結的一些常用到的事件 1.監聽標簽內容變化 非input元素 $(dom).bind(‘DOMNodeInserted‘,func

瀏覽器事件封裝

tar color UNC spa src eve and prevent elb var EventUtil = { // 添加事件處理程序 addHandler: function (element,type,handler) {

JS瀏覽器事件循環機制

由於 分享圖片 span 條件 計時不準確 clas 次循環 all 問題 文章來自我的 github 博客,包括技術輸出和學習筆記,歡迎star。 先來明白些概念性內容。 進程、線程 進程是系統分配的獨立資源,是 CPU 資源分配的基本單位,進程是由一個或者多個線程組

紅芯瀏覽器事件

雲適配 谷歌瀏覽器 入口 認證 style href 幫助 核心 什麽 紅芯公司宣布融資當天,紅芯瀏覽器被曝出打開安全目錄後出現大量和谷歌 chrome 瀏覽器一致的同名文件,其安裝程序的文件屬性中也顯示了原始文件名 chrome.exe。   8 月 15 日,號

瀏覽器事件機制

class 觸發 highlight inner med content classname tel iat 事件被觸發三階段   1. document往事件觸發處傳播,會觸發遇到註冊的捕獲事件;   2. 傳播到事件觸發處,觸發註冊事件;   3. 從事件觸發處往doc

時事點評-紅芯瀏覽器事件

思想 作文 定義 是否 什麽 號稱 有一個 多公司 支持 一、8月16日,號稱自護創新的紅芯瀏覽器被曝套用谷歌chrome瀏覽器,而其所宣稱的安全功能也並不安全,其代碼遭廣大程序員吐槽。 二、我的評論:從漢芯到紅芯,這些號稱有“中國心”的自主研發產品都有一個共同特點——他們

時事點評——紅芯瀏覽器事件

業務 容易 邏輯 事件 alt 一個 info 什麽 image 一、紅芯瀏覽器事件 8月15日,處於風口浪尖的紅芯瀏覽器因註釋過多冗雜,安全性低下在網上引起了程序員群嘲。 二、我的評論 三、我認同的觀點 1、我覺得程序註釋是很重要的,一方面方便自己,再者方便於團隊開發,

軟件作業2:時事點評-紅芯瀏覽器事件

瀏覽器 積累 定義 教程 com 功能 壟斷 碼農 聲明 一、紅芯事件 事件描述 自稱“打破美國壟斷,中國首個自主創新智能瀏覽器內核”的紅芯瀏覽器被發現註釋過度,安全性低,且出現大量與谷歌瀏覽器Chrome一樣的文件,與其自稱的創新不符。 二、我的評論 我認為程序中可以

時事點評-紅芯瀏覽器事件 --“國產”究竟有多遠?

頭條 下載 http 我認 都得 今日頭條 com 關註 get 一、紅芯事件 8月16日上午,打著“中國首個自主創新智能瀏覽器內核”旗號紅芯瀏覽器遭到網友和部分媒體“打臉”。8月17日,在輿論持續發酵

事件點評————紅芯瀏覽器事件

認同 技術分享 chrome 評論 str ron 中國 rom alt 一、紅芯瀏覽器事件 8月26日,中國首個自主創新智能瀏覽器內核的紅芯瀏覽器拿到了2.5億融資,但是被爆抄襲Chrome瀏覽器的內核。 二、我的評論 三、我認同的觀點 事件點評————紅芯

軟工作業 2:時事點評-紅芯瀏覽器事件

pan 兩件 http 技術 ima 瀏覽器內核 方便 alt strong 一:紅芯瀏覽器事件 “中國首個自主創新智能瀏覽器內核”的紅芯瀏覽器被爆抄襲,內部代碼引人爭議。 二:我的觀點 我覺得註釋是必不可少的,無論是便於他人接手時的閱讀,還是

軟工作業2:時事點評-紅芯瀏覽器事件

語言 過度 代碼冗余 發出 創新 軟工 程序 1.26 nbsp 一、紅芯事件 8月16日,自稱“打破美國壟斷,中國首個自主創新智能瀏覽器內核”的紅芯瀏覽器,被網友發現“只是谷歌瀏覽器換了一層皮”——紅芯瀏覽器安裝包解壓後發現,最終可以得到一個版本號為49.1.2623.2

自定義瀏覽器事件,模擬瀏覽器事件

簡述 我認為,事件是我們前端最為熟悉的程式設計模式,在前端開發中能接觸太多太多,而且相對而言,事件是一種相對容易理解,邏輯性高的的模式,對於優化元件/外掛的邏輯是一個很好的應用模式。 這文章主要是用JavaScript實現3級dom事件機制,後面的更新會涉及應用倒元件開發當中。