connection - Is there a way to detect whether user is on wifi or cellular data with javascript? - Stack Overflow

I want the video to autoplay on the website only if the user is connected to the wifi. I know about the

I want the video to autoplay on the website only if the user is connected to the wifi. I know about the navigator.connection api - but it's not available on safari, and besides it only tells you about the speed of the connection not the type.

I want the video to autoplay on the website only if the user is connected to the wifi. I know about the navigator.connection api - but it's not available on safari, and besides it only tells you about the speed of the connection not the type.

Share Improve this question asked Feb 24, 2018 at 20:43 spongebobspongebob 1811 silver badge9 bronze badges 1
  • A similar question was asked here: stackoverflow./questions/25968020/… Hope that's helpful! – ShanaSkydancer Commented Feb 24, 2018 at 20:49
Add a ment  | 

1 Answer 1

Reset to default 5

As of December 2020, Safari has made no moves to implement the Network Information API, which as you've noted, provides the navigator.connection NetworkInformation object. That's a shame, because other browsers have supplied this for years.

This means there is no equivalent of the iOS-native Reachability APIs on mobile Safari (or desktop Safari, for that matter), so the best you can do is to use a very rough hack like:

  • looking up the user's public IP and trying to match it to a database of cell providers, or
  • making a test download to roughly gauge connection speed.

For the sake of pleteness, according to the MDN, the browsers that do provide navigator.connection as of December 2020, are:

  • Desktop:
    • Chrome 61+
    • Edge 79+
    • Firefox, but only if the user has enabled the dominfo.enabled preference
    • Opera
  • Mobile:
    • Android WebView 50+
    • Chrome Android 38+
    • Firefox Android 14+ (same caveat as desktop)
    • Opera Android 37+
    • Samsung Internet 3+

(Safari and Internet Explorer are the only major browsers conspicuously missing support.)

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745451790a4628304.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信