if (!navigator.onLine) {
args.forEach((para) => {
if (typeof para === 'function') {
try {
para('message.offline');
} catch (e) {
}
}
});
this.offline();
return;
}
protected offline() {
const dom = `
<div id="offline">
<span>×</span>
<div class="body">
<p>无法连接到网络,请检查网络连接</p>
<img src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMDAgMTAwIj48ZGVmcz48c3R5bGU+LmNscy0xe2ZpbGw6IzAwMzY1NztvcGFjaXR5OjA7fS5jbHMtMntmaWxsOiNkM2QzZDM7fS5jbHMtM3tmaWxsOiNlNWU1ZTU7fS5jbHMtNHtmaWxsOiNlZmVmZWY7fS5jbHMtNXtmaWxsOiNkZmRmZGY7fS5jbHMtNntmaWxsOiNlOGU4ZTg7fS5jbHMtN3tmaWxsOiNhOGE4YTg7fTwvc3R5bGU+PC9kZWZzPjx0aXRsZT5pbnRlcm5ldF9kaXNjb25uZWN0ZWQ8L3RpdGxlPjxnIGlkPSLlm77lsYJfMiIgZGF0YS1uYW1lPSLlm77lsYIgMiI+PGcgaWQ9IuWbvuWxgl8xLTIiIGRhdGEtbmFtZT0i5Zu+5bGCIDEiPjxyZWN0IGNsYXNzPSJjbHMtMSIgd2lkdGg9IjEwMCIgaGVpZ2h0PSIxMDAiIHRyYW5zZm9ybT0idHJhbnNsYXRlKDAgMTAwKSByb3RhdGUoLTkwKSIvPjxjaXJjbGUgY2xhc3M9ImNscy0yIiBjeD0iNTUuMDQiIGN5PSI3OC42NyIgcj0iNC43MSIgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoLTM0LjY5IDExMi44NCkgcm90YXRlKC03NS44NykiLz48ZWxsaXBzZSBjbGFzcz0iY2xzLTMiIGN4PSI1NS43NyIgY3k9Ijc1Ljc4IiByeD0iNC43NCIgcnk9IjE4LjEiIHRyYW5zZm9ybT0idHJhbnNsYXRlKC0zMS4zMyAxMTEuMzYpIHJvdGF0ZSgtNzUuODcp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wLDAsMCw3My40NSw4MC44NFptLTItLjI0TDcyLDgxbC0xLjI3LjE1Wm0tMS4xNS0uMzZhLjczLjczLDAsMCwwLC4zNi4xbC0uNDIuMzFhMi42MywyLjYzLDAsMCwxLS4xLS41N0ExLDEsMCwwLDAsNzAuMjksODAuMjRaIi8+PC9nPjwvZz48L3N2Zz4=" alt="">
</div>
</div>
`;
let timer;
const removeDom = () => {
$('#offline').remove();
clearInterval(timer);
};
if (document.getElementById('offline') == null) {
$('body').append(dom);
timer = setInterval(() => {
if (navigator.onLine) {
removeDom();
}
}, 2000);
}
$('#offline span').click(removeDom);
}
11-19
2197
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
03-27
530
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
11-25
4210
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)