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/document/ononline/index.html | 40 ++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 files/zh-cn/web/api/document/ononline/index.html (limited to 'files/zh-cn/web/api/document/ononline') diff --git a/files/zh-cn/web/api/document/ononline/index.html b/files/zh-cn/web/api/document/ononline/index.html new file mode 100644 index 0000000000..8a98a300eb --- /dev/null +++ b/files/zh-cn/web/api/document/ononline/index.html @@ -0,0 +1,40 @@ +--- +title: Document.ononline +slug: Web/API/Document/ononline +tags: + - API + - 原型 + - 文档 + - 文档说明 + - 方法 + - 页面文档 +translation_of: Web/API/Document/ononline +--- +

{{APIRef("DOM")}}

+ +

当浏览器在联机和脱机模式之间切换时,会在每个页面的<body>触发online事件此外,这些事件从document.body,到document结束于window。这两个事件(在线状态或离线状态)都是不可取消的(您无法阻止用户进入在线状态或离线状态)。

+ +

如果浏览器处于联机状态,window.navigator.onLine将返回布尔值true,如果它 处于脱机状态(从网络断开连接),则返回false。当此属性的值更改时,会触发联机和脱机事件。

+ +
+

重要的是要注意,这个事件和属性本质上是不可靠的。计算机可以连接到网络而无需访问Internet。

+
+ +

您可以用几种常见的方法监听这些事件:

+ + + +

例子

+ +

一个简单的测试用例,你可以运行,以验证该事件工作。

+ +

参考

+ + -- cgit v1.2.3-54-g00ecf