当前位置:网站首页>纯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')
边栏推荐
- Shutter control layout
- Six necessary open source projects for private activities
- 【第25天】给定一个长度为 n 的数组,统计每个数出现的次数 | 计数哈希
- PMP Exam related calculation formula summary! Must see before examination
- Three types of transactions in EF core (saveChanges, dbcontexttransaction, transactionscope)
- Cloud native architecture (05) - Application Architecture Evolution
- I was cheated by my colleagues to work overtime on weekends. I haven't seen redis used like this...
- [interview experience package] summary of experience of being hanged during interview (I)
- 数据库中索引原理及填充因子
- 如何利用数仓创建时序表
猜你喜欢

Interview notes for Android outsourcing workers for 3 years. You still need to go to a large factory to learn and improve when you have the opportunity. Interview questions for Android Development Int
![[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)

Usage of go in SQL Server

Taylor formula and common expansion

Use of reverse tools IDA and GDB

Save: software analysis, verification and test platform

Generate all possible binary search trees

Windows10 security mode entry cycle blue screen repair

This high imitation millet mall project is amazing

docker redis集群配置
随机推荐
Web site SSL certificate
[FreeRTOS] 07 binary semaphore and count semaphore
物联网卡设备接入EasyCVR,如何查看拉流IP以及拉流时间?
Usage of go in SQL Server
docker 部署redis
Revit API: schedule viewschedule
[proteus simulation] example of T6963C driving pg12864 (with Chinese and English display)
Test - use case - detail frenzy
测试 - 用例篇 - 细节狂魔
元宇宙中的社会秩序
What is the future development of palmprint recognition technology?
Three Solution to the problem of inaccuracy in radiographic testing under the condition of non full screen canvas of JS
Return, const, volatile keywords
解决项目依赖报红问题
生成所有可能的二叉搜索树
Salesforce batch apex batch processing (V) asyncapexjob intelligence
2. camera calibration
Jeecgboot old version 2 x 3. X how to integrate building block reports?
国内首款开源MySQL HTAP数据库即将发布,三大看点提前告知 石原子科技重磅推出
The easycvr program started abnormally as a service, but the process started normally. What is the reason?