【问题标题】:How do I change this to detect Desktops instead of mobile? [closed]如何更改它以检测台式机而不是移动设备? [关闭]
【发布时间】:2020-08-12 18:20:41
【问题描述】:

如何更改它以检测桌面?

<script language=javascript>
<!--
if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
   location.replace("http://url-to-send-them/iphone.html");
}
-->
</script>

【问题讨论】:

  • 你可以加“!”在这样的第一个括号之后,它将使陈述相反。比如:if (!(navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) { location.replace("url-to-send-them/iphone.html"); }

标签: javascript device detection


【解决方案1】:

您不想只按设备大小/宽度来做吗?

如果没有,您可能可以使用一个工具:http://hgoebl.github.io/mobile-detect.js/

但是this 可能会有所帮助,如果您只是在做一些不需要基于不同操作系统进行特定更改的“简单”操作。如果您能提供更多信息,那也会有所帮助。希望对您有所帮助!

这个选项与你已有的类似:

    <script type="text/javascript">
      var isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent);
      if (isMobile) {
          // do something...
      } else {
          // do something else...
      }
    </script>

有几种方法可以解决这个问题,但取决于您究竟想要做什么(从示例代码的外观来看,您只是想加载一个不同的HTML 页面)。

【讨论】:

    猜你喜欢
    • 2017-05-16
    • 2015-10-19
    • 2013-05-21
    • 2021-05-21
    • 2015-03-20
    • 1970-01-01
    • 1970-01-01
    • 2015-01-06
    相关资源
    最近更新 更多