【问题标题】:Best way to know which device type is requesting website? [duplicate]了解请求网站的设备类型的最佳方法是什么? [复制]
【发布时间】:2013-05-28 13:40:42
【问题描述】:

了解请求网站的设备类型的最佳方法是什么?

我想知道哪个设备(台式机/笔记本电脑/手机/平板电脑等)正在使用 java script/j-query 或 c# 代码向我的网站生成请求。

我还想知道更多细节:

设备屏幕分辨率 操作系统名称 浏览器名称和版本 请求 IP 地址 设备编号 位置

有什么办法可以得到以上所有细节...请建议。

【问题讨论】:

  • 这无疑是一个有趣的问题!对于某些人来说,使用所见即所得的编辑器会更好。大多数现代编辑器都可以在程序本身中做到这一点。
  • @pattyd 它可能很有趣,但它并不比关于这个主题的其他问题更有趣。重复之前所说的答案确实没有用,我们最好将所有知识整合到一个问题中。这就是 Close as Duplicate 功能的用途。
  • @CodeCaster 是的,我同意你的看法。我也标记了它...
  • 你会接受答案吗?

标签: c# javascript jquery


【解决方案1】:

WURFL project 正是为此目的而启动的。它将客户端提供的User-Agent 字符串解析为功能、输入法、设备类型等的列表。有APIs for all common serverside languages,提供tons of properties

【讨论】:

    【解决方案2】:

    使用请求标头字段,您可以找到我们访问的对象...

    例如:

    if(request.getHeader("User-Agent").indexOf("Mobile") != -1) {
    
    }
    

    http://en.wikipedia.org/wiki/List_of_HTTP_header_fields

    【讨论】:

      【解决方案3】:

      您可以使用此 JavaScript 代码(找到 here)在用户屏幕上获取一些信息。
      然后,您可以设置一个条件来检查屏幕尺寸是否为平板电脑、手机、计算机等的尺寸...

      <script>
      document.write("Total width/height: ");
      document.write(screen.width + "*" + screen.height);
      document.write("<br>");
      document.write("Available width/height: ");
      document.write(screen.availWidth + "*" + screen.availHeight);
      document.write("<br>");
      document.write("Color depth: ");
      document.write(screen.colorDepth);
      document.write("<br>");
      document.write("Color resolution: ");
      document.write(screen.pixelDepth);
      </script>
      

      至于操作系统,我目前不确定。如果我找到更多信息,我将编辑此答案。我希望这会有所帮助!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-11-07
        • 1970-01-01
        • 2019-11-18
        • 1970-01-01
        • 2012-06-20
        • 1970-01-01
        • 2010-10-12
        相关资源
        最近更新 更多