title: How do I redirect a page based on the browser user agent?
body: <p>I am using this script to detect the string "safari" in the user agent header which then redirects you to "android.html" how would I change the code to make it so it redirects if the user agent header does NOT contain "safari"?</p>
  
  <pre><code>var ua = navigator.userAgent.toLowerCase();
  var isAndroid = ua.indexOf("safari") &gt; -1; //&amp;&amp; ua.indexOf("mobile");
  if(isAndroid) {
  window.location = 'android.html';
  }
  </code></pre>
  
  <p><strong>EDIT:</strong>
  Here is my revised code. Does this make sense? It first detects whether the device is android or not then it redirects if it is a safari browser.</p>
  
  <pre><code>var ua = navigator.userAgent.toLowerCase();
      var isAndroid = ua.indexOf("android") &gt; -1;
      var isSafari = ua.indexOf("safari") == -1;
          if(isAndroid) {
          if(isSafari) {
          window.location = 'android.html';
          }
          }
  </code></pre>