var connection = Navigator.connection | | navigator.mozconnection | | navigator.webkitconnection | | {tyep: ' unknown '};var type_text = [' Unknown ', ' Ethernet ', ' WiFi ', ' 2g ', ' 3g ', ' 4g ', ' None '];alert (Connection.type); var r E_el = document.getElementById ("Re"), var btn_el = document.getElementById ("btn"), function Get_status () {if (typeof (Co Nnection.type) = = "Number") {connection.type_text = Type_text[connection.type]; } else {connection.type_text = Connection.type; } if (typeof (connection.bandwidth) = = "Number") {if (Connection.bandwidth >) {Connection.typ e = ' WiFi '; } else if (Connection.bandwidth > 2) {connection.type = ' 3g '; } else if (Connection.bandwidth > 0) {connection.type = ' 2g '; } else if (Connection.bandwidth = = 0) {Connection.type = ' none '; } else {connection.type = ' unknown '; }} var html = ' Type: ' + connection.type_text; Html + = ' Bandwidth: ' + connection.bandwidth; HTML + = ' IsOnline: ' + navigator.online; re_el.innerhtml = html;} Btn_el.onclick = function () {re_el.innerhtml = ' waiting ... '; Get_status ();}
JS Judging WiFi and traffic