title: Best way to detect mobile device and redirect
body: <p>Here's my snippet for detecting a mobile display based on the screen size. You can force the site to stay in desktop-mode by adding a forceDesktop param to the URL. </p>
  
  <p>I`m new to jquery so if you have suggestions, please comment.</p>
  
  <p>Credits go to brandonjp:
  <a href="https://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript/2480180#2480180">How can I get query string values in JavaScript?</a></p>
  
  <pre><code>        &lt;script&gt;
              $.urlParam = function(name, url) {
                  if (!url) {
                      url = window.location.href;
                  }
                  var results = new RegExp('[\\?&amp;]' + name + '=([^&amp;#]*)').exec(url);
                  if (!results) { 
                      return undefined;
                  }
                  return results[1] || undefined;
              }
              window.onload = function() {
                  var forceDesktop = $.urlParam('forceDesktop');
                  if (!forceDesktop) {
                      if ( $(window).width() &lt; 639) {   
                          var url = "http://m.mysite.com/";    
                          $(location).attr('href',url);
                      }
                  }
              };
          &lt;/script&gt;
  </code></pre>