1

How do I change this to detect desktops?

<script language=javascript>
<!--
if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
   location.replace("http://url-to-send-them/iphone.html");
}
-->
</script>
Silviu Burcea
  • 4,573
  • 1
  • 24
  • 41
  • you can add "!" after the first bracket like this it will make the statement opposite. like: if (!(navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) { location.replace("http://url-to-send-them/iphone.html"); } – Muhammad Ali Apr 28 '20 at 19:45

1 Answers1

0

Would you not want to just do it by device size/width?

If not, there is a tool you might be able to use: http://hgoebl.github.io/mobile-detect.js/

But this might help if you're just doing something "simple" that doesn't require specific changes based on different OS's. If you can provide more information, that will help as well. Hope it helps!

There is this option that is similar to what you already have:

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

There are several ways to go about this, but depends on what exactly you're trying to get it to do (from the looks of your sample code, you're just wanting to load a different HTML page).

Jeff Berlin
  • 550
  • 5
  • 15