title: Detect iOS 5 or Higher with JavaScript
body: <p>I'm trying to use the following script to detect whether the browser is iOS 5 or higher (from this SO thread <a href="https://stackoverflow.com/questions/8348139/detect-ios-version-less-than-5-with-javascript">Detect iOS version less than 5 with JavaScript</a>).</p>
  
  <pre><code>function iOSversion() {
      if (/iP(hone|od|ad)/.test(navigator.platform)) {
          var v = (navigator.appVersion).match(/OS (\d+)_(\d+)_?(\d+)?/);
          return [parseInt(v[1], 10), parseInt(v[2], 10), parseInt(v[3] || 0, 10)];
      }
  }
  
  ver = iOSversion();
  
  if (ver[0] &gt;= 5) {
      alert('This is running iOS 5 or later.');
  } else {
      alert('This is NOT running iOS 5 or later.');
  }
  </code></pre>
  
  <p>It works in iOS 5 or later as it should, but in any other browser it produces the following error:</p>
  
  <pre><code>Uncaught TypeError: Cannot read property '0' of undefined 
  </code></pre>
  
  <p>And then all JavaScript below this script fails.</p>
  
  <p>Please can someone advise how I can fix this?? Thank you.</p>