区分移动端H5断网后操作

if(navigator.onLine) {  // true false
	alert('连网情况下进行操作')
} else {
	alert('断网情况下进行操作');
	layer.msg('网络异常')
}

navigator对象如下


txt = "

浏览器代号: " + navigator.appCodeName + "

"
; txt+= "

浏览器名称: " + navigator.appName + "

"
; txt+= "

浏览器版本: " + navigator.appVersion + "

"
; txt+= "

启用Cookies: " + navigator.cookieEnabled + "

"
; txt+= "

硬件平台: " + navigator.platform + "

"
; txt+= "

用户代理: " + navigator.userAgent + "

"
; txt+= "

用户代理语言: " + navigator.systemLanguage + "

"
; document.getElementById("example").innerHTML=txt;

解析如下

浏览器代号: Mozilla

浏览器名称: Netscape

浏览器版本: 5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36

启用Cookies: true

硬件平台: Win32

用户代理: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36

用户代理语言: undefined

你可能感兴趣的:(js)