JS 检查网络

50 阅读1分钟

JS检查网络是否可以使用谷歌搜索

使用 Image 加载一张Google官方的 LOGO

var img = new Image(); 
img.addEventListener('load', function() {
  console.log('Google is accessible')
}, false);
img.src = 'https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png';

注意!!! 由于图片在浏览器中存在缓存问题,开发阶段需要每次需要清理缓存,关闭浏览器才能正确检查