Pages

Showing posts with label javascript. Show all posts
Showing posts with label javascript. Show all posts

Friday, February 14, 2014

Detetar dispositivo móvel em javascript numa página

Segue aqui um helper em javascript para detetar qual o dispositivo móvel que está a carregar a página:

  var isMobile = {  
    Android: function() {  
      return navigator.userAgent.match(/Android/i) ? true : false;  
    },  
    BlackBerry: function() {  
      return navigator.userAgent.match(/BlackBerry/i) ? true : false;  
    },  
    iOS: function() {  
      return navigator.userAgent.match(/iPhone|iPad|iPod/i) ? true : false;  
    },  
    Windows: function() {  
      return navigator.userAgent.match(/IEMobile/i) ? true : false;  
    },  
    any: function() {  
      return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Windows());  
    }  
  };  


Fonte: DETECTING MOBILE DEVICES WITH JAVASCRIPT