【问题标题】:Is there a way to detect 3G and 2G connections speed on mobile phones and handheld devices?有没有办法检测手机和手持设备上的 3G 和 2G 连接速度?
【发布时间】:2023-03-12 05:41:02
【问题描述】:

有没有办法检测手机和手持设备上的 3G 和 2G 连接?

如果我想在用户使用 3G 时提供高端网站,如果用户使用 2G 时提供高度优化版本。

【问题讨论】:

    标签: mobile-website mobile-phones browser-feature-detection html5-animation device-detection


    【解决方案1】:

    在 Android 2.2+ 中有一个 JS 对象。

    您可以根据连接类型编写一个供 CSS 使用的类。 但据我所知,它不适用于 iOS 上的移动网站。

    var connection, connectionSpeed, htmlNode, htmlClass;
    connection = navigator.connection || {"type":"0"}; // fallback
    
    switch(connection.type) {
      case connection.CELL_3G: connectionSpeed = "mediumbandwidth"; break;
      case connection.CELL_2G: connectionSpeed = "lowbandwidth"; break;
      default: connectionSpeed = 'highbandwidth';
    }
    
    /* set the connection speed on the html element
       i.e. <html class="lowbandwidth">
    */
    htmlNode = document.body.parentNode;
    htmlClass = htmlNode.getAttribute("class") || "";
    htmlNode.setAttribute("class", htmlClass + " " + connectionSpeed);
    

    代码来自本演示文稿的第 24 张幻灯片:
    http://davidbcalhoun.com/present/mobile-performance/

    【讨论】:

      【解决方案2】:

      某些网络将连接类型作为 http 标头发送。

      您最好的选择是在用户连接时进行速度测试,并尝试将其作为 cookie 存储在客户端上

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-11-10
        • 1970-01-01
        相关资源
        最近更新 更多