当前位置:网站首页>纯js实现判断ip是否ping通
纯js实现判断ip是否ping通
2022-06-23 22:23:00 【乐辞】
最近在做一个需求时要考虑到网络环境是否能够访问,于是写了一段代码
function ping(address) {
var img = new Image();
var start = new Date().getTime();
var hasFinish = false;
img.onload = function() {
if ( !hasFinish ) {
hasFinish = true;
console.log('Ping ' + address + ' success. ');
}
};
img.onerror = function() {
hasFinish = false;
console.log('Ping ' + address + ' fail.. ');
};
img.src = address + '/?' + start;
setTimeout(()=>{
if(hasFinish){
hasFinish = false
console.log('There is a problem with your network, please refresh the page and try again.');
}
},1500)
}
ping('https://developers.facebook.com/favicon.ico')
边栏推荐
- [technical grass planting] the tail of the "double 11" event. Let's talk about how much discount the message push service package is!
- Facebook open source shimmer effect
- Shutter time selector
- Chaos engineering, learn about it
- Classical Chinese can be programmed???
- [new cos series] | object storage cos data Vientiane CI processing special data processing resource package 4.5 folded into a big gift package!
- 1. < tag dynamic programming and path combination problem > lt.62 Different paths + lt.63 Different paths II
- 生成所有可能的二叉搜索树
- 依赖倒置原则
- CPU取指到发出控制、微程序控制原理详细过程
猜你喜欢
![[interview experience package] summary of experience of being hanged during interview (I)](/img/ab/ccee8e624248840e712c0b4ca417dd.png)
[interview experience package] summary of experience of being hanged during interview (I)

人工智能技术岗位面试要注意什么?

1. < tag dynamic programming and path combination problem > lt.62 Different paths + lt.63 Different paths II

Cloud native architecture (05) - Application Architecture Evolution

【图像检测显著图】基于matlab失真提示鱼眼图显著图计算【含Matlab源码 1903期】

extern、struct等关键字
![[FreeRTOS] 07 binary semaphore and count semaphore](/img/9c/a3e4b9e02f754c5d3a54d94b7b4e35.png)
[FreeRTOS] 07 binary semaphore and count semaphore

NLP工程师是干什么的?工作内容是什么?

国内首款开源MySQL HTAP数据库即将发布,三大看点提前告知 石原子科技重磅推出

Dependency Inversion Principle
随机推荐
【第25天】给定一个长度为 n 的数组,统计每个数出现的次数 | 计数哈希
mcu常用寄存器位操作方式汇总
暑假第一周
Shutter time selector
First week of summer vacation
并发和并行有什么区别?
Revit API: schedule viewschedule
Kubernetes basic concept
NLP工程师是干什么的?工作内容是什么?
Salesforce Future method in salesforce – @future
元宇宙中的社会秩序
【数字信号】基于matlab模拟窗函数频谱细化【含Matlab源码 1906期】
Test - use case - detail frenzy
Design of message push platform
Windows10 security mode entry cycle blue screen repair
Perfectionist win10 installation guide
Facebook open source shimmer effect
Quantitative investment model -- research interpretation of high frequency trading market making model (Avellaneda & Stoikov's) & code resources
Total number of combinations ii[each element can only be solved by + once]
Hackers can gain administrator privileges by invading Microsoft mail server and windows Zero Day vulnerability November 23 global network security hotspot