Window:online 事件
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
当浏览器能够访问网络,且 Navigator.onLine
的值被设为 true
时,Window
接口的 online
事件将被触发。
备注: 该事件不能用于确定某个网站可否访问。网站自身问题或防火墙都有可能阻止对特定网站的访问。
示例
js
// addEventListener version
window.addEventListener("online", (event) => {
console.log("You are now connected to the network.");
});
// ononline version
window.ononline = (event) => {
console.log("You are now connected to the network.");
};
规范
Specification |
---|
HTML Standard # event-online |
HTML Standard # handler-window-ononline |
浏览器兼容性
BCD tables only load in the browser