NetworkInformation:change 事件
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
备注: 此特性在 Web Worker 中可用。
NetworkInformation
接口的 change
事件在网络连接信息发生变化时被触发,并且该事件由 NetworkInformation
对象接收。
语法
在类似 addEventListener()
这样的方法中使用事件名称,或者设置事件处理器属性。
js
addEventListener("change", (event) => {});
onchange = (event) => {};
事件类型
一个通用的 Event
。
示例
js
// 获取网络连接类型。
const type = navigator.connection.type;
function changeHandler(e) {
// 在此处理网络连接类型的更改。
}
// 注册监听活动变更:
navigator.connection.onchange = changeHandler;
// 另一种方式:navigator.connection.addEventListener('change', changeHandler);
规范
Specification |
---|
Network Information API # dom-networkinformation-onchange |
浏览器兼容性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
change event |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- No support
- No support
- See implementation notes.
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.