WindowEventHandlers

WindowEventHandlers mixin describes the event handlers common to several interfaces like Window ,或 HTMLBodyElement and HTMLFrameSetElement . Each of these interfaces can implement additional specific event handlers.

注意 : WindowEventHandlers is a mixin and not an interface; you can't actually create an object of type WindowEventHandlers .

特性

The events properties, of the form onXYZ , are defined on the WindowEventHandlers , and implemented by Window ,和 WorkerGlobalScope for Web Workers.

WindowEventHandlers.onafterprint
Is an EventHandler representing the code to be called when the afterprint event is raised.
WindowEventHandlers.onbeforeprint
Is an EventHandler representing the code to be called when the beforeprint event is raised.
WindowEventHandlers.onbeforeunload
Is an EventHandler representing the code to be called when the beforeunload event is raised.
WindowEventHandlers.onhashchange
Is an EventHandler representing the code to be called when the hashchange event is raised.
WindowEventHandlers.onlanguagechange
Is an EventHandler representing the code to be called when the languagechange event is raised.
WindowEventHandlers.onmessage
Is an EventHandler representing the code to be called when the message event is raised.
WindowEventHandlers.onmessageerror
Is an EventHandler representing the code to be called when the MessageError event is raised.
WindowEventHandlers.onoffline
Is an EventHandler representing the code to be called when the offline event is raised.
WindowEventHandlers.ononline
Is an EventHandler representing the code to be called when the online event is raised.
WindowEventHandlers.onpagehide
Is an EventHandler representing the code to be called when the pagehide event is raised.
WindowEventHandlers.onpageshow
Is an EventHandler representing the code to be called when the pageshow event is raised.
WindowEventHandlers.onpopstate
Is an EventHandler representing the code to be called when the popstate event is raised.
WindowEventHandlers.onrejectionhandled
Is an EventHandler representing the code to be called when the rejectionhandled event is raised, indicating that a Promise was rejected and the rejection has been handled.
WindowEventHandlers.onstorage
Is an EventHandler representing the code to be called when the storage event is raised.
WindowEventHandlers.onunhandledrejection
Is an EventHandler representing the code to be called when the unhandledrejection event is raised, indicating that a Promise was rejected but the rejection was not handled.
WindowEventHandlers.onunload
Is an EventHandler representing the code to be called when the unload event is raised.

方法

This interface defines no method.

规范

规范 状态 Comment
HTML Living Standard
The definition of 'WindowEventHandlers' in that specification.
实时标准 No change since the latest snapshot, HTML 5.1 .
HTML 5.1
The definition of 'WindowEventHandlers' in that specification.
Recommendation Snapshot of HTML Living Standard . Added onlanguage since the HTML5 snapshot.
HTML5
The definition of 'WindowEventHandlers' in that specification.
Recommendation Snapshot of HTML Living Standard . Creation of WindowEventHandlers (properties where on the target before it).

浏览器兼容性

更新 GitHub 上的兼容性数据
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
WindowEventHandlers Chrome Yes Edge 12 Firefox Yes IE Yes Opera Yes Safari Yes WebView Android Yes Chrome Android Yes Firefox Android Yes Opera Android Yes Safari iOS Yes Samsung Internet Android Yes
onafterprint Chrome 63 Edge 12 Firefox 6 IE Yes Opera 50 Safari 13 WebView Android 63 Chrome Android 63 Firefox Android ? Opera Android 46 Safari iOS 13 Samsung Internet Android 8.0
onbeforeprint Chrome 63 Edge 12 Firefox 6 IE Yes Opera 50 Safari 13 WebView Android 63 Chrome Android 63 Firefox Android ? Opera Android 46 Safari iOS 13 Samsung Internet Android 8.0
onbeforeunload Chrome 1 Edge 12 Firefox 1 IE 4 Opera 12 Safari 3 WebView Android 1 Chrome Android 18 Firefox Android 4 Opera Android 12 Safari iOS 1 Samsung Internet Android 1.0
onhashchange Chrome 5 Edge 12 Firefox 3.6 IE 8 Opera 10 Safari 5 WebView Android ≤37 Chrome Android 18 Firefox Android 4 Opera Android 10.1 Safari iOS 5 Samsung Internet Android 1.0
onlanguagechange
Chrome 37 Edge ≤79 Firefox 32 IE No Opera 24 Safari ? WebView Android 37 Chrome Android 37 Firefox Android 4 Opera Android 24 Safari iOS ? Samsung Internet Android 4.0
onmessage Chrome 60 Edge ≤79 Firefox ? IE ? Opera 47 Safari ? WebView Android 60 Chrome Android 60 Firefox Android ? Opera Android 44 Safari iOS ? Samsung Internet Android 8.0
onmessageerror Chrome 60 Edge ≤79 Firefox 57 IE ? Opera 47 Safari ? WebView Android 60 Chrome Android 60 Firefox Android 57 Opera Android 44 Safari iOS ? Samsung Internet Android 8.0
onpopstate Chrome 5 Edge 12 Firefox 4 IE 10 Opera 11.5 Safari 6 WebView Android 37 Chrome Android 18 Firefox Android 4 Opera Android 11.5 Safari iOS 5.1 Samsung Internet Android 1.0
onrejectionhandled Chrome 49 Edge ≤79 Firefox 69
69
68
Disabled
Disabled From version 68: this feature is behind the dom.promise_rejection_events.enabled preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
部分支持 55
Disabled
This event handler was added in Firefox 55 but was disabled since it wasn't fully implemented. It was fully implemented in Firefox 68 and enabled by default in Firefox 69.
Disabled From version 55: this feature is behind the dom.promise_rejection_events.enabled preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
IE No Opera 36 Safari 11 WebView Android 49 Chrome Android 49 Firefox Android 68
Disabled
68
Disabled
Disabled From version 68: this feature is behind the dom.promise_rejection_events.enabled preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
部分支持 55
Disabled
This event handler was added in Firefox 55 but was disabled since it wasn't fully implemented. It was fully implemented in Firefox 68 but not enabled by default.
Disabled From version 55: this feature is behind the dom.promise_rejection_events.enabled preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
Opera Android No Safari iOS 11.3 Samsung Internet Android 5.0
onstorage Chrome 1 Edge ≤18 Firefox 45 IE ? Opera 15 Safari ? WebView Android ≤37 Chrome Android 18 Firefox Android 45 Opera Android 14 Safari iOS ? Samsung Internet Android 1.0
onunhandledrejection Chrome 49 Edge ≤79 Firefox 69
69
68
Disabled
Disabled From version 68: this feature is behind the dom.promise_rejection_events.enabled preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
部分支持 55
Disabled
This event handler was added in Firefox 55 but was disabled since it wasn't fully implemented. It was fully implemented in Firefox 68 and enabled by default in Firefox 69.
Disabled From version 55: this feature is behind the dom.promise_rejection_events.enabled preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
IE No Opera 36 Safari 11 WebView Android 49 Chrome Android 49 Firefox Android 68
Disabled
68
Disabled
Disabled From version 68: this feature is behind the dom.promise_rejection_events.enabled preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
部分支持 55
Disabled
This event handler was added in Firefox 55 but was disabled since it wasn't fully implemented. It was fully implemented in Firefox 68 but not enabled by default.
Disabled From version 55: this feature is behind the dom.promise_rejection_events.enabled preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
Opera Android No Safari iOS 11.3 Samsung Internet Android 5.0
onunload Chrome Yes Edge 12 Firefox Yes IE Yes Opera Yes Safari Yes WebView Android Yes Chrome Android Yes Firefox Android Yes Opera Android Yes Safari iOS Yes Samsung Internet Android Yes

图例

完整支持
完整支持
不支持
不支持
兼容性未知
兼容性未知
实验。期望将来行为有所改变。
实验。期望将来行为有所改变。
见实现注意事项。
用户必须明确启用此特征。
用户必须明确启用此特征。

另请参阅

  1. WindowEventHandlers
  2. 特性
    1. onafterprint
    2. onbeforeprint
    3. onbeforeunload
    4. onhashchange
    5. onlanguagechange
    6. onmessage
    7. onmessageerror
    8. onpopstate
    9. onrejectionhandled
    10. onstorage
    11. onunhandledrejection
    12. onunload
  3. 实现通过:
    1. HTMLBodyElement
    2. HTMLFrameSetElement
    3. Window
  4. Related pages for HTML DOM
    1. BeforeUnloadEvent
    2. DOMStringMap
    3. ErrorEvent
    4. GlobalEventHandlers
    5. HTMLAnchorElement
    6. HTMLAreaElement
    7. HTMLAudioElement
    8. HTMLBRElement
    9. HTMLBaseElement
    10. HTMLBaseFontElement
    11. HTMLBodyElement
    12. HTMLButtonElement
    13. HTMLCanvasElement
    14. HTMLContentElement
    15. HTMLDListElement
    16. HTMLDataElement
    17. HTMLDataListElement
    18. HTMLDialogElement
    19. HTMLDivElement
    20. HTMLDocument
    21. HTMLElement
    22. HTMLEmbedElement
    23. HTMLFieldSetElement
    24. HTMLFormControlsCollection
    25. HTMLFormElement
    26. HTMLFrameSetElement
    27. HTMLHRElement
    28. HTMLHeadElement
    29. HTMLHeadingElement
    30. HTMLHtmlElement
    31. HTMLIFrameElement
    32. HTMLImageElement
    33. HTMLInputElement
    34. HTMLIsIndexElement
    35. HTMLKeygenElement
    36. HTMLLIElement
    37. HTMLLabelElement
    38. HTMLLegendElement
    39. HTMLLinkElement
    40. HTMLMapElement
    41. HTMLMediaElement
    42. HTMLMetaElement
    43. HTMLMeterElement
    44. HTMLModElement
    45. HTMLOListElement
    46. HTMLObjectElement
    47. HTMLOptGroupElement
    48. HTMLOptionElement
    49. HTMLOptionsCollection
    50. HTMLOutputElement
    51. HTMLParagraphElement
    52. HTMLParamElement
    53. HTMLPictureElement
    54. HTMLPreElement
    55. HTMLProgressElement
    56. HTMLQuoteElement
    57. HTMLScriptElement
    58. HTMLSelectElement
    59. HTMLShadowElement
    60. HTMLSourceElement
    61. HTMLSpanElement
    62. HTMLStyleElement
    63. HTMLTableCaptionElement
    64. HTMLTableCellElement
    65. HTMLTableColElement
    66. HTMLTableDataCellElement
    67. HTMLTableElement
    68. HTMLTableHeaderCellElement
    69. HTMLTableRowElement
    70. HTMLTableSectionElement
    71. HTMLTemplateElement
    72. HTMLTextAreaElement
    73. HTMLTimeElement
    74. HTMLTitleElement
    75. HTMLTrackElement
    76. HTMLUListElement
    77. HTMLUnknownElement
    78. HTMLVideoElement
    79. HashChangeEvent
    80. History
    81. ImageData
    82. Location
    83. MessageChannel
    84. MessageEvent
    85. MessagePort
    86. Navigator
    87. NavigatorGeolocation
    88. NavigatorID
    89. NavigatorLanguage
    90. NavigatorOnLine
    91. NavigatorPlugins
    92. PageTransitionEvent
    93. Plugin
    94. PluginArray
    95. PopStateEvent
    96. PortCollection
    97. PromiseRejectionEvent
    98. RadioNodeList
    99. Transferable
    100. ValidityState
    101. Window
    102. WindowBase64
    103. WindowTimers