Determine user's internet connection type via javascript or jquery

核能气质少年 提交于 2019-12-12 01:43:58

问题


I'm using javascript to lookup a user's location based on the IP address. It works great for everything except cellular networks (which, unfortunately, is the bulk of my site's visitors). For cellular connections, the location is often off by 100 miles or more.

A stripped down version of the site is here: http://autopilothomelistings.com/ab/geoip13.html

I'm trying to figure out a way to determine if a visitor to my site is on a wireless connection or on Wifi/LAN, so that I can display alternate content depending on the connection type, but I haven't found a suitable answer. I can check for the device or browser, but these are not helpful, since a 'mobile' device can either be on wifi (which results in an accurate location) or on cellular (which is inaccurate).

I found a few threads that were somewhat relevant, but didn't ultimately provide any help:

1.) Thread discussing Apple's Reachability class: How to identify internet connection type and it's current speed

2.) Thread discussing navigator.connection: How do I check connection type (WiFi/LAN/WWAN) using HTML5/JavaScript? - which look promising in theory, but when I looked at the documentation here: https://developer.mozilla.org/en-US/docs/Web/API/NetworkInformation.connection - it appears to unsupported by the major browsers.

3.) Thread that uses javascript to determine connection speed: How to Determine Connection Type in JavaScript

Any ideas are greatly appreciated. I'm hoping there is an easy way to check the connection type on the client-side.


回答1:


Directly speaking you cannot.

There is currently a Draft in w3.org Here, which gives informtion,It is experimental.But at present only selected & update browsers support that method.

Mozilla has even not defined it in its compatibility report, but you can see its parent class compatibility Here, which shows that this method is still far behind.

There are still some methods available like iOS,Windows APP, PhoneGAP (They support because they have built an application. Here is information on API)



来源:https://stackoverflow.com/questions/23772390/determine-users-internet-connection-type-via-javascript-or-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!