Skip to content

Instantly share code, notes, and snippets.

@handleman
Created February 12, 2014 14:23
Show Gist options
  • Select an option

  • Save handleman/8956416 to your computer and use it in GitHub Desktop.

Select an option

Save handleman/8956416 to your computer and use it in GitHub Desktop.
Определение мобильного браузера пользователя
;window.mobileDetection = {
Android:function () {
return navigator.userAgent.match(/Android/i);
},
BlackBerry:function () {
return navigator.userAgent.match(/BlackBerry/i);
},
iOS:function () {
return navigator.userAgent.match(/iPhone|iPad|iPod/i);
},
Opera:function () {
return navigator.userAgent.match(/Opera Mini/i);
},
Windows:function () {
return navigator.userAgent.match(/IEMobile/i);
},
any:function () {
return (this.Android() || this.BlackBerry() || this.iOS() || this.Opera() || this.Windows());
}};
// ПОльзоваться так
/*
window.isMobile = mobileDetection.any() // Вернет true, если сидим с мобильника
window.isMobile = mobileDetection.iOS() // Вернет true, если сидим с iPhone или iPad
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment