Skip to content

Instantly share code, notes, and snippets.

@armand1m
Last active September 2, 2015 13:14
Show Gist options
  • Save armand1m/a719ab6e80e62c2e68bb to your computer and use it in GitHub Desktop.
Save armand1m/a719ab6e80e62c2e68bb to your computer and use it in GitHub Desktop.
Verifica se o navegador está usando um User Agent que o identifique como dispositivo mobile.
/**
* Verifica se o navegador está usando um User Agent que o identifique
* como dispositivo mobile.
*
* @return bool
* @author Armando Magalhães
*/
function hasMobileUserAgent() {
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/.test(navigator.userAgent);
}
/**
* Verifica se é um navegador mobile.
*
* @return bool
* @author Armando Magalhães
*/
function isMobile() {
return hasMobileUserAgent() && window.matchMedia("(max-width: 640px)").matches;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment