From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- files/zh-cn/web/api/windoweventhandlers/index.html | 189 +++++++++++++++++++++ .../windoweventhandlers/onafterprint/index.html | 107 ++++++++++++ .../windoweventhandlers/onbeforeprint/index.html | 62 +++++++ .../onlanguagechange/index.html | 101 +++++++++++ .../api/windoweventhandlers/onmessage/index.html | 84 +++++++++ .../windoweventhandlers/onmessageerror/index.html | 119 +++++++++++++ .../api/windoweventhandlers/onstorage/index.html | 98 +++++++++++ 7 files changed, 760 insertions(+) create mode 100644 files/zh-cn/web/api/windoweventhandlers/index.html create mode 100644 files/zh-cn/web/api/windoweventhandlers/onafterprint/index.html create mode 100644 files/zh-cn/web/api/windoweventhandlers/onbeforeprint/index.html create mode 100644 files/zh-cn/web/api/windoweventhandlers/onlanguagechange/index.html create mode 100644 files/zh-cn/web/api/windoweventhandlers/onmessage/index.html create mode 100644 files/zh-cn/web/api/windoweventhandlers/onmessageerror/index.html create mode 100644 files/zh-cn/web/api/windoweventhandlers/onstorage/index.html (limited to 'files/zh-cn/web/api/windoweventhandlers') diff --git a/files/zh-cn/web/api/windoweventhandlers/index.html b/files/zh-cn/web/api/windoweventhandlers/index.html new file mode 100644 index 0000000000..72a8a78eb9 --- /dev/null +++ b/files/zh-cn/web/api/windoweventhandlers/index.html @@ -0,0 +1,189 @@ +--- +title: WindowEventHandlers +slug: Web/API/WindowEventHandlers +tags: + - API + - HTML-DOM + - Interface + - NeedsTranslation + - Reference + - TopicStub +translation_of: Web/API/WindowEventHandlers +--- +
{{APIRef("HTML DOM")}}
+ +

WindowEventHandlers mixin 描述了事件处理程序常见的一些公共接口 ,例如{{domxref("Window")}}和 {{domxref("HTMLBodyElement")}} 和 {{domxref("HTMLFrameSetElement")}}等这些接口都实现了下列特定的事件处理程序。

+ +

WindowEventHandlers不是一个接口,没有这种类型的对象可以创建。

+ +

Properties

+ +

The events properties, of the form onXYZ, are defined on the {{domxref("WindowEventHandlers")}}, and implemented by {{domxref("Window")}}, and {{domxref("WorkerGlobalScope")}} for Web Workers.

+ +
+
{{domxref("WindowEventHandlers.onafterprint")}}
+
Is an {{domxref("EventHandler")}} representing the code to be called when the {{event("afterprint")}} event is raised.
+
{{domxref("WindowEventHandlers.onbeforeprint")}}
+
Is an {{domxref("EventHandler")}} representing the code to be called when the {{event("beforeprint")}} event is raised.
+
{{domxref("WindowEventHandlers.onbeforeunload")}}
+
Is an {{domxref("EventHandler")}} representing the code to be called when the {{event("beforeunload")}} event is raised.
+
{{domxref("WindowEventHandlers.onhashchange")}}
+
Is an {{domxref("EventHandler")}} representing the code to be called when the {{event("hashchange")}} event is raised.
+
{{domxref("WindowEventHandlers.onlanguagechange")}} {{experimental_inline}}
+
Is an {{domxref("EventHandler")}} representing the code to be called when the {{event("languagechange")}} event is raised.
+
{{domxref("WindowEventHandlers.onmessage")}}
+
Is an {{domxref("EventHandler")}} representing the code to be called when the {{event("message")}} event is raised.
+
{{domxref("WindowEventHandlers.onoffline")}}
+
Is an {{domxref("EventHandler")}} representing the code to be called when the {{event("offline")}} event is raised.
+
{{domxref("WindowEventHandlers.ononline")}}
+
Is an {{domxref("EventHandler")}} representing the code to be called when the {{event("online")}} event is raised.
+
{{domxref("WindowEventHandlers.onpagehide")}}
+
Is an {{domxref("EventHandler")}} representing the code to be called when the {{event("pagehide")}} event is raised.
+
{{domxref("WindowEventHandlers.onpageshow")}}
+
Is an {{domxref("EventHandler")}} representing the code to be called when the {{event("pageshow")}} event is raised.
+
{{domxref("WindowEventHandlers.onpopstate")}}
+
Is an {{domxref("EventHandler")}} representing the code to be called when the {{event("popstate")}} event is raised.
+
{{domxref("WindowEventHandlers.onstorage")}}
+
Is an {{domxref("EventHandler")}} representing the code to be called when the {{event("storage")}} event is raised.
+
{{domxref("WindowEventHandlers.onunhandledrejection")}} {{experimental_inline}}
+
An event handler for unhandled {{jsxref("Promise")}} rejection events.
+
{{domxref("WindowEventHandlers.onunload")}}
+
Is an {{domxref("EventHandler")}} representing the code to be called when the {{event("unload")}} event is raised.
+
+ +

Methods

+ +

This interface defines no method.

+ +

Specifications

+ + + + + + + + + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('HTML WHATWG', '#windoweventhandlers', 'GlobalEventHandlers')}}{{Spec2('HTML WHATWG')}}No change since the latest snapshot, {{SpecName("HTML5.1")}}.
{{SpecName('HTML5.1', '#windoweventhandlers', 'GlobalEventHandlers')}}{{Spec2('HTML5.1')}}Snapshot of {{SpecName("HTML WHATWG")}}. Added onlanguage since the {{SpecName("HTML5 W3C")}} snapshot.
{{SpecName("HTML5 W3C", "#windoweventhandlers", "GlobalEventHandlers")}}{{Spec2('HTML5 W3C')}}Snapshot of {{SpecName("HTML WHATWG")}}. Creation of WindowEventHandlers (properties where on the target before it).
+ +

Browser compatibility

+ +

{{CompatibilityTable}}

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FeatureFirefox (Gecko)ChromeInternet ExplorerOperaSafari
Basic support{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
onhashchange{{CompatGeckoDesktop(1.9.2)}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
onlanguage{{experimental_inline}}{{CompatGeckoDesktop(32)}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
onstorage{{CompatGeckoDesktop(45)}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FeatureFirefox Mobile (Gecko)AndroidIE MobileOpera MobileSafari Mobile
Basic support{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
onhashchange{{CompatGeckoMobile(1.9.2)}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
onlanguage{{experimental_inline}}{{CompatGeckoMobile(32)}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
onstorage{{CompatGeckoDesktop(45)}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
+
+ +

See also

+ + diff --git a/files/zh-cn/web/api/windoweventhandlers/onafterprint/index.html b/files/zh-cn/web/api/windoweventhandlers/onafterprint/index.html new file mode 100644 index 0000000000..cdf54dcead --- /dev/null +++ b/files/zh-cn/web/api/windoweventhandlers/onafterprint/index.html @@ -0,0 +1,107 @@ +--- +title: WindowEventHandlers.onafterprint +slug: Web/API/WindowEventHandlers/onafterprint +tags: + - 打印 +translation_of: Web/API/WindowEventHandlers/onafterprint +--- +
{{ApiRef}}
+ +

{{domxref("WindowEventHandlers")}}的onafterprint属性是用于处理当前窗口的{{event("afterprint")}}事件的{{domxref("EventHandler")}}。这些事件会在被用户打印结束或者中止打印窗口的情况下触发。

+ +

{{event("beforeprint")}}和afterprint 事件允许页面在打印开始前修改它们的内容(比如移除一个横幅等),打印结束后,这些修改会恢复原状。一般情况下,你更喜欢使用 @media print CSS规则,但是在某些情况下这些事件会有他们的必要性。

+ +

语法

+ +
window.addEventListener("afterprint", function(event) { ... });
+window.onafterprint = event handling code
+
+ +

提示

+ +

某些浏览器(包括 Firefox 6 及更高版本和 Internet Explorer)用触发beforeprintafterprint的方式来确定何时进行了打印。你可以在打印期间用这个方式来调整用户界面(UI)的表现(比如在打印过程中展示或隐藏一些界面元素)。

+ +

afterprint会在用户打印完成或取消打印会话后触发。

+ +

规范

+ + + + + + + + + + + + + + +
Specification 规范Status 状态Comment 备注
{{SpecName('HTML WHATWG', '/multipage/webappapis.html#windoweventhandlers', 'onafterprint')}}{{Spec2('HTML WHATWG')}}
+ +

浏览器兼容性

+ +

{{CompatibilityTable}}

+ +
+ + + + + + + + + + + + + + + + + + + + + +
FeatureChromeEdgeFirefox (Gecko)Internet ExplorerOperaSafari
Basic support{{CompatNo}}{{CompatVersionUnknown}}6.0{{CompatVersionUnknown}}{{CompatNo}}{{CompatNo}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
FeatureAndroid WebviewChrome for AndroidEdgeFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
{{CompatUnknown}}{{CompatNo}}{{CompatNo}}{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatNo}}{{CompatUnknown}}
+
+ +

更多请见

+ + + +
diff --git a/files/zh-cn/web/api/windoweventhandlers/onbeforeprint/index.html b/files/zh-cn/web/api/windoweventhandlers/onbeforeprint/index.html new file mode 100644 index 0000000000..834ca04cf0 --- /dev/null +++ b/files/zh-cn/web/api/windoweventhandlers/onbeforeprint/index.html @@ -0,0 +1,62 @@ +--- +title: WindowEventHandlers.onbeforeprint +slug: Web/API/WindowEventHandlers/onbeforeprint +translation_of: Web/API/WindowEventHandlers/onbeforeprint +--- +
{{ApiRef}}
+ +
{{domxref("WindowEventHandlers")}}的onbeforeprint属性是用于处理当前窗口的{{event("beforeprint")}}事件的{{domxref("EventHandler")}}。在打开打印对话窗口之前会触发这些事件。
+ +
+ +
beforeprint{{event("afterprint")}}事件允许网页在打印开始前更改他们的内容(例如:可能是删除一个横幅),然后在打印完成后恢复这些更改。通常,您应该更喜欢使用@media printCSS规则,但是在某些情况下可能有必要使用这些事件。
+ +

语法

+ +
window.addEventListener("beforeprint", function(event) { ... });
+window.onbeforeprint = function(event) { ... };
+
+ +

范例

+ +

Safari没有实现这些事件,但是您可以使用创建与beforeprint事件等效的结果{{domxref("window.matchMedia")}}('print')

+ +
var mediaQueryList = window.matchMedia('print');
+mediaQueryList.addListener(function(mql) {
+  if(mql.matches) {
+    console.log('webkit equivalent of onbeforeprint');
+  }
+});
+ +

规范

+ + + + + + + + + + + + + + + + +
规范状态注解
{{SpecName('HTML WHATWG', '#handler-window-onbeforeprint', 'onbeforeprint')}}{{Spec2('HTML WHATWG')}}
+ +

浏览器兼容性

+ + + +

{{Compat("api.WindowEventHandlers.onbeforeprint")}}

+ +

参阅

+ + diff --git a/files/zh-cn/web/api/windoweventhandlers/onlanguagechange/index.html b/files/zh-cn/web/api/windoweventhandlers/onlanguagechange/index.html new file mode 100644 index 0000000000..ccabcc1c2e --- /dev/null +++ b/files/zh-cn/web/api/windoweventhandlers/onlanguagechange/index.html @@ -0,0 +1,101 @@ +--- +title: WindowEventHandlers.onlanguagechange +slug: Web/API/WindowEventHandlers/onlanguagechange +translation_of: Web/API/WindowEventHandlers/onlanguagechange +--- +

{{APIRef("HTML DOM")}}{{SeeCompatTable}}

+ +

WindowEventHandlers.onlanguagechange 事件是一个属性,包含待执行的代码。当 {{domxref("Event")}} 类型的 {{event("languagechange")}} 事件被这些接口实现的对象(如 {{domxref("Window")}}、{{domxref("HTMLBodyElement")}} 或者 {{domxref("HTMLIFrameElement")}} 等对象)触发时,该事件属性的代码将被运行。这样的事件在浏览器通知更佳的语言列表已被更新后被触发。关于语言列表的介绍,您可访问:{{domxref("NavigatorLanguage.languages")}}。

+ +

语法

+ +
object.onlanguagechange = function;
+
+ +

+ + + +

例子

+ +
window.onlanguagechange = function(ev) { alert("languagechange event detected!"); };
+
+ +

标准

+ + + + + + + + + + + + + + + + +
标准状态备注
{{ SpecName('HTML WHATWG', '#handler-workerglobalscope-onlanguagechange', 'WindowEventHandler.onlanguagechange') }}{{ Spec2('HTML WHATWG') }}初始版本
+ +

浏览器兼容性

+ +

{{ CompatibilityTable() }}

+ +
+ + + + + + + + + + + + + + + + + + + +
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari
基础支持{{ CompatUnknown() }}{{ CompatGeckoDesktop(32.0) }}{{ CompatNo() }}{{ CompatUnknown() }}{{ CompatUnknown() }}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
FeatureAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
基础支持{{ CompatUnknown() }}{{ CompatUnknown() }}{{ CompatGeckoMobile(32.0) }}{{ CompatNo() }}{{ CompatUnknown() }}{{ CompatUnknown() }}
+
+ +

参见

+ + diff --git a/files/zh-cn/web/api/windoweventhandlers/onmessage/index.html b/files/zh-cn/web/api/windoweventhandlers/onmessage/index.html new file mode 100644 index 0000000000..bdbcdc3f2f --- /dev/null +++ b/files/zh-cn/web/api/windoweventhandlers/onmessage/index.html @@ -0,0 +1,84 @@ +--- +title: onmessage +slug: Web/API/WindowEventHandlers/onmessage +translation_of: Web/API/WindowEventHandlers/onmessage +--- +

{{APIRef("HTML DOM")}}{{ SeeCompatTable() }}

+ +

{{domxref("WindowEventHandlers")}}的onmessage 属性是当对象接收到{{event("message")}} 事件时被调用的{{domxref("EventHandler")}} .

+ +

语法

+ +
window.addEventListener('message', function(event) { ... })
+window.onmessage = function(event) { ... }
+ +

规范

+ + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('HTML WHATWG','#handler-window-onmessage','onmessage')}}{{Spec2('HTML WHATWG')}}Initial definition.
+ +

浏览器兼容性

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
Basic support{{CompatChrome(60)}}{{CompatUnknown}}{{CompatUnknown}}{{CompatOpera(47)}}{{CompatUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
FeatureAndroid WebviewChrome for AndroidFirefox Mobile (Gecko)Firefox OSIE MobileOpera MobileSafari Mobile
Basic support{{CompatChrome(60)}}{{CompatChrome(60)}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatOperaMobile(47)}}{{CompatUnknown}}
+
diff --git a/files/zh-cn/web/api/windoweventhandlers/onmessageerror/index.html b/files/zh-cn/web/api/windoweventhandlers/onmessageerror/index.html new file mode 100644 index 0000000000..609f9a9923 --- /dev/null +++ b/files/zh-cn/web/api/windoweventhandlers/onmessageerror/index.html @@ -0,0 +1,119 @@ +--- +title: WindowEventHandlers.onmessageerror +slug: Web/API/WindowEventHandlers/onmessageerror +translation_of: Web/API/WindowEventHandlers/onmessageerror +--- +
{{APIRef("HTML DOM")}}
+ +

 

+ +

{{domxref("WindowEventHandlers")}}接口的onmessageerror事件处理器是一个 {{domxref("EventListener")}},每当一个类型为 messageerror 的 {{domxref("EventListener")}} 事件在一个窗口被触发 --也就是说,当它收到的消息不能是{{glossary("Deserialization", "deserialized")}} 。

+ +

{{AvailableInWorkers}}

+ +

 

+ +

语法

+ +
window.onmessageerror = function() { ... };
+ +

规范

+ + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('HTML WHATWG', '#handler-window-onmessageerror', 'onmessageerror')}}{{Spec2('HTML WHATWG')}} 
+ +

浏览器兼容性

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FeatureChromeEdgeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
Basic support{{CompatChrome(60)}}{{CompatUnknown}}{{CompatGeckoDesktop(57)}}{{CompatUnknown}}{{CompatOpera(47)}}{{CompatUnknown}}
Available in workers{{CompatChrome(60)}}{{CompatUnknown}}{{CompatGeckoDesktop(57)}}{{CompatUnknown}}{{CompatOpera(47)}}{{CompatUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FeatureAndroid WebviewChrome for AndroidEdgeFirefox Mobile (Gecko)Firefox OS (Gecko)IE PhoneOpera MobileSafari Mobile
Basic support{{CompatChrome(60)}}{{CompatChrome(60)}}{{CompatUnknown}}{{CompatGeckoMobile(57)}}{{CompatUnknown}}{{CompatUnknown}}{{CompatOpera(47)}}{{CompatUnknown}}
Available in workers{{CompatChrome(60)}}{{CompatChrome(60)}}{{CompatUnknown}}{{CompatGeckoMobile(57)}}{{CompatUnknown}}{{CompatUnknown}}{{CompatOpera(47)}}{{CompatUnknown}}
+
+ +

See also

+ + diff --git a/files/zh-cn/web/api/windoweventhandlers/onstorage/index.html b/files/zh-cn/web/api/windoweventhandlers/onstorage/index.html new file mode 100644 index 0000000000..fe7dc2a7cc --- /dev/null +++ b/files/zh-cn/web/api/windoweventhandlers/onstorage/index.html @@ -0,0 +1,98 @@ +--- +title: WindowEventHandlers.onstorage +slug: Web/API/WindowEventHandlers/onstorage +tags: + - API + - Web Storage + - WindowEventHandlers + - 属性 +translation_of: Web/API/WindowEventHandlers/onstorage +--- +
{{ ApiRef() }}
+ +

WindowEventHandlers.onstorage 属性包含一个在{{event("storage")}}事件触发时的事件句柄。 

+ +

注意:该事件不在导致数据变化的当前页面触发(如果浏览器同时打开一个域名下面的多个页面,当其中的一个页面改变 sessionStoragelocalStorage 的数据时,其他所有页面的  storage  事件会被触发,而原始页面并不触发 storage 事件)

+ +

语法

+ +
windowObj.onstorage = function() { ... };
+ +

用例

+ +
window.onstorage = function(e) {
+  console.log( e.key + ' 键已经从 ' + e.oldValue + ' 改变为 ' + e.newValue + '.');
+};
+ +

说明书

+ + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('HTML WHATWG','webappapis.html#handler-window-onstorage','onstorage')}}{{Spec2('HTML WHATWG')}}
+ +

浏览器兼容性

+ +

{{CompatibilityTable}}

+ +
+ + + + + + + + + + + + + + + + + + + +
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
Basic support{{CompatUnknown}}{{CompatGeckoDesktop(45)}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
FeatureAndroidAndroid WebviewFirefox Mobile (Gecko)Firefox OSIE MobileOpera MobileSafari MobileChrome for Android
Basic support{{CompatUnknown}}{{CompatUnknown}}{{CompatGeckoMobile(45)}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
+
-- cgit v1.2.3-54-g00ecf