title: How do I detect browser and mobile together? JavaScript
body: <p>I am trying to recognize the browser with javascript so I can play a video fullscreen or just display an alert, I can recognize chrome and safari and all of them fine on laptops/desktops, it's just when I try to also recognize if the device is mobile it does not work. I do not get the alert I am trying to get. I tried this: <a href="https://stackoverflow.com/a/3540295">https://stackoverflow.com/a/3540295</a>. But I had no luck, among other things like this(the Original Answer because I am not sure what regex is?): <a href="https://stackoverflow.com/a/11381730">https://stackoverflow.com/a/11381730</a><br>
  I have this now. I want to use User Agent unless there is a better way.<br>
  JS:</p>
  
  <pre class="lang-js prettyprint-override"><code>function goFullscreen(id) {
    var element = document.getElementById(id); 
    var mobile = /Android|webOS|iPhone|iPad|iPod/i.test(navigator.userAgent);
  
    if (ua.indexOf('safari') != -1) { 
        if (ua.indexOf('chrome') &gt; -1) {
          if (element.webkitRequestFullScreen) {
              if(mobile) {
                  // some code for chrome mobile
                  alert("chrome mobile")
              }else{
                  //document.getElementById(id).classList.toggle("videoChange")
                  alert("chrome desktop")
              }
          }
        } else if (element.msRequestFullscreen) {
              element.msRequestFullscreen(); //edge do somethig else
        } else if (element.mozRequestFullScreen) {
              element.mozRequestFullScreen(); //mozilla do somethig else  
        } else if (element.webkitRequestFullScreen) {
               if(mobile) {
                   // some code for safari mobile
                   alert("safari mobile")
               }else{
                  element.webkitRequestFullScreen(); //safari do somethig else
               }
  
          }
      }
  }
  </code></pre>