내가 알고 있는 regex 함수를 사용할 수 있지만, 너무 다양한 사용자 에이전트 쓰기 '와' 나비가토리우스라그랑 사용하여 다른 플랫폼용. 과연 그럴까요, 내가 생각하기에 이 문제가 쉽게 해결되지 않을 것 "이라며 가능한 모든 디바이스에는 경기 전에 작업을 위한 완벽한 솔루션 등 여러 차례 그러하매 함정이거나 있어야 합니다.
제가 볼 때 [이 사이트] (http://detectmobilebrowsers.com), 정말 아무 생각이 너무 모호 하지만 안타깝게도 스크립트입니다 how to use it for my 목적 함수를 만들 수 있으며, 이는 복귀하십시오 참 / 거짓.
window.mobilecheck = function() {
var check = false;
(function(a){if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0,4))) check = true;})(navigator.userAgent||navigator.vendor||window.opera);
return check;
};
이 테스트에서 하는 사람들을 위해 포함시키십시오 태블릿 (표시되어도 shouldn& 시각이 잘 드러나 있습니다 # 39, t), 같은 기능을 사용할 수 있습니다.
window.mobileAndTabletcheck = function() {
var check = false;
(function(a){if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino|android|ipad|playbook|silk/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0,4))) check = true;})(navigator.userAgent||navigator.vendor||window.opera);
return check;
};
이 경우 장치 및 검사를 통해 실행 할 수 있는 것만으로도 바뀌엇어요 우저지나 이런걸 일치시킵니다 있습니다.
function detectmob() {
if( navigator.userAgent.match(/Android/i)
|| navigator.userAgent.match(/webOS/i)
|| navigator.userAgent.match(/iPhone/i)
|| navigator.userAgent.match(/iPad/i)
|| navigator.userAgent.match(/iPod/i)
|| navigator.userAgent.match(/BlackBerry/i)
|| navigator.userAgent.match(/Windows Phone/i)
){
return true;
}
else {
return false;
}
}
그러나 이후 이 방법을 사용할 수 있는 신뢰할 수 있는 것으로 판단되는 모든 디바이스입니다 결의안을 이하) 은 모바일 장치를 인도하심이라만일 solaris. 800x600 의 범위를 좁혀 대상 역시 더욱 (단, 이 보다 훨씬 더 많은 모바일 장치는 요즘 해상도)
이리에
function detectmob() {
if(window.innerWidth <= 800 && window.innerHeight <= 600) {
return true;
} else {
return false;
}
}
어때.
if (typeof window.orientation !== 'undefined') { ... }
일반적으로 재산 및 데스크탑 브라우저 don& # 39, 이를 지지하는 스진스 스마트폰 없다.
var isMobile = {
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) || navigator.userAgent.match(/WPDesktop/i);
},
any: function() {
return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
}
};
사용 방법
if( isMobile.any() ) alert('Mobile');
User 가 특정 모바일 장치에서 수 있는지 확인합니다.
if( isMobile.iOS() ) alert('iOS');
Ref: http://www.abeautifulsite.net/blog/2011/11/detecting-mobile-devices-with-javascript
깃허브 대한 강화된 버전: https://github.com/smali-kazmi/detect-mobile-browser
여기 와서 간단한 방법을 찾고 있는 것처럼, 나는 클래스용 devices" " 탐지합니다 청소하십시오 터치 스크린, 모바일 및 태블릿 pc. 하지만 현재 답을 찾지 못한 일을 아웃해야 수 있는 깨끗한 솔루션으로서의 다음과 같은 사람이 될 수도 있다.
var touchDevice = ('ontouchstart' in document.documentElement);
var touchDevice = (navigator.maxTouchPoints || 'ontouchstart' in document.documentElement);
<! - begin 스니핏: js 숨기십시오: > 거짓값 -;
/ 아이폰 / i, c = b = {var! 함수 (a) = / 아이패드 / i / iPod/i, d, e = 비트/ (?) = .\bAndroid\b) (?) = .\bMobile\b) / i, f, g = Android/i = / / (?) = .\bAndroid\b) (?) = .\bSD4930UR\b), h = /i / (?) = .\bAndroid\b) (?) = .\b (? 크포트 크프트 크프제비 크프제바 크프소비 크프트위 크프스웨 크파프비 크파프와 사파르비 크파스비 크프스웨이 크프사와) \b) / i, i = /iemobile/i = / / i, j, k = /blackberry/i (?) = .\bwindows\b) (?) = .\barm\b), l, m, n = = = / / 오페라 bb10/i mini/i /i / (크리오 크롬) (?) = .\bmobile\b), o = /i / (?) = .\bfirefox\b) (?) = .*\bmobile\b), p = 새 정규 표현식 (". (? 넥서스 7 bntv250 킨들 파이어 비단 gt p1000) " i" ";;), q = 함수 (a, b) {} {var 복귀하십시오 아스테스트 (b), r = r = a, s = 리스프리트 나비가토리우스라그랑 함수 (a) (" 1an"), return", undefined"! = 메리 페로프 s 1 &, &. (r = s [0]), s = 리스프리트 (", twitter"), ", undefined"! = 메리 페로프 s 1 &, &. (r = s [0]), 티s.애플 = {전화번호:) q (b, r), 아이팟 q (c, r), 태블릿:! q (b, r) &, &, q (d, r), 디바이스입니다 q (b, r) q (c, r) q (d, r)}, 티스트라마초니 = {전화 q (g, r), 태블릿:! q (g, r) &, &, q (h, r), 디바이스입니다 q (g, r) q (h, r)}, 티s.안드로이드 = {전화 q (g, r) q (e, r), 태블릿:! q (g, r) &, &! q (e, r) &, &, (q (h, r) q (f, r), 디바이스입니다 q (g, r) q (h, r) q (e, r) q (f (r)}, 스이스윈드로스 = {전화 q (i, r), 태블릿 q (j, r), 디바이스입니다 q (i, r) q (j, r)}, 스이제이더 = {블랙베리 q (k, r), blackberry10 q (l, r), 오페라 q (m, r), firefox q (o, r), 크롬 q (n, r), 디바이스입니다 q (k, r) q (l, r) q (m, r) q (o, r) q (n, r)}, this.seven_inch = q (p, r), 토리오니 = 티스트라플러스데이비스 티s.안드로이트러스데이비스 티s.빈다우스자드비스 티s.더스데이비스 this.seven_inch, 티스윈포네 = 티스트라프레스포네 티s.안드로이드리포네 스이스윈드로스윈포네, 스이스터블트 = 티스트라플스터블트 티s.안드로이드스터블트 스이스윈드로스스터블트, ", undefined" = 메리 페로프 창? 이: void 0}, {var = new r, s = 함수 () 는 반환합니다. Class = r 은};;;;;;;! = 메리 페로프 " undefined" module& & module.exports& & " undefined";;;;! = = = r:" undefined" 메리 페로프 module& & 모두레드릭스포르츠 메리 페로프 창?;;;;;! = 메리 페로프 module.exports& & " undefined" 모두레드릭스포르츠 = s (), 창, & define& 메리 페로프 function" :"??;; = 데프린스마드 정의 (,, [], 앨리스모빌레 " isMobile" = s ()) = s ()} :a.isMobile (이);
alert(isMobile.any ? 'Mobile' : 'Not mobile');
끝 - < 스니핏 >;!
이 코드는 특정 브라우저 스니핑 있는 라리브러리 호출됨 아모빌레 .
'빈다우드로리엔테이션 세그먼트인지를 테스트하는' 에 규정되어 있다.
<! - begin 스니핏: js 숨기십시오: > 거짓값 -;
<! - 언어: > js 랭 -; var 아모빌레 = 빈다우드로리엔테이션 >. - 1. 경고 (아모빌레? # 39, & # 39 Mobile&. . # 39, & # 39 mobile& 있지 않습니다.). 끝 - < 스니핏 >;!
_
일부 터치스크린 장치는 모바일, 그 반대의 경우도 마찬가지입니다. 따라서 구현하기 위해 특별히 뭔가 스케쳐내 전날에약혼자에게 shouldn& # 39 는 터치스크린, t 모바일 장치에서 실행하십시오 브라우저를 세그먼트인지를 테스트하는 것이 아니라 나열할지 디바이스에는 는 터치스크린 지원:
<! - begin 스니핏: js 숨기십시오: > 거짓값 -;
<! - 언어: > js 랭 -;
경고 (해스투흐스린? # 39, & # 39 는 touchscreen&. . # 39, & # 39 doesn\& touchscreen& # 39 없다;;). 끝 - < 스니핏 >;!
내가 사용하는 스토리지 제어할 수 있는 HTML5 에서 추가 레이어에는 탐지합니다 모바일을 이용한 경우 저장소나 데스크탑입니다 스토리지. 나는 있지만브라우저에 경우 모바일 브라우저 이름 쉐퍼드도 배열입니다 스토지 지원하지 않는 브라우저를 통해 사용자 에이전트 비교할 수 있는 어레이입니다.
그것은 아주 단순합니다. 다음은 기능:
// Used to detect whether the users browser is an mobile browser
function isMobile() {
///<summary>Detecting whether the browser is a mobile browser or desktop browser</summary>
///<returns>A boolean value indicating whether the browser is a mobile browser or not</returns>
if (sessionStorage.desktop) // desktop storage
return false;
else if (localStorage.mobile) // mobile storage
return true;
// alternative
var mobile = ['iphone','ipad','android','blackberry','nokia','opera mini','windows mobile','windows phone','iemobile'];
for (var i in mobile) if (navigator.userAgent.toLowerCase().indexOf(mobile[i].toLowerCase()) > 0) return true;
// nothing found.. assume desktop
return false;
}
많아 의존하고 있다고 움직이는 대상으로 사용자 에이전트 데이터 문제가 있다. 화면 크기를 계산할 수 있는 같은 위한 것 "이라고 말했다. Css 는 터치 인터페이스 기술을 빌려 내 외곽진입 판단할 수 있다. 순결케 사용하여 javascript (현대의 모든 의 지원 브라우저) 때 쉽게 확인할 수 있습니다, 미디어 쿼리하지 디바이스: 모바일.
function isMobile() {
var match = window.matchMedia || window.msMatchMedia;
if(match) {
var mq = match("(pointer:coarse)");
return mq.matches;
}
return false;
}
이 보다 더 효율적인 일치시킵니다 우저지나 솔루션이다.
function _isMobile(){
// if we want a more complete list use this: http://detectmobilebrowsers.com/
// str.test() is more efficent than str.match()
// remember str.test is case sensitive
var isMobile = (/iphone|ipod|android|ie|blackberry|fennec/).test
(navigator.userAgent.toLowerCase());
return isMobile;
}
정말 좋은 방법이 있으면 만들 수 있는 모바일 터치 감지 또는 tablet 디바이스에는 있지만브라우저에 이벤트 () 이다.
일반 자바스크립트 코드:
function isMobile() {
try{ document.createEvent("TouchEvent"); return true; }
catch(e){ return false; }
}
if (isMobile()) {
# do whatever you wanna do!
}
하지만 이 협력했습니다 가져다줄래요 정말로 잘 랩톱에서 터치스크린 디스플레이 장치를 포함하는 문제가 있을 수 있습니다.
나는 내가 haven& 터치스크린 노트북 등 모바일 디바이스 검출하였습니다 경우 얻을 수 있는지 알고 있기 때문에 아직 # 39, t 테스트되었습니다.
그러나 사용자 에이전트 수단으로 사용해야 하는 경우, 그들은 모바일 디바이스이면 탐지합니다 제안하세요:
>. 요약하자면, 문자열 "Mobi" 어느 곳에서나 찾는 것이 좋습니다. >. 사용자 에이전트 감지하기 위해 모바일 장치.
이 때문에 한 줄 광고문 충분할 것이다.
const 아모빌레드비스 = 빈다우드나비가토리우스라그랑스톨로베르케이스 () ',' 지의 크루즈 (mobi" ";)
내 다시 생각 슬라이드에서는 솔루션 제공 문제. 아직 완벽하지 않아. 진정한 솔루션 업체들이 약간만이라도 디바이스이면 시작할 수 있는 " 농담하십니까 시행하십시오 Mobile"; 및 " Tablet"; 사용자 에이전트 문자열을.
window.onload = userAgentDetect;
function userAgentDetect() {
if(window.navigator.userAgent.match(/Mobile/i)
|| window.navigator.userAgent.match(/iPhone/i)
|| window.navigator.userAgent.match(/iPod/i)
|| window.navigator.userAgent.match(/IEMobile/i)
|| window.navigator.userAgent.match(/Windows Phone/i)
|| window.navigator.userAgent.match(/Android/i)
|| window.navigator.userAgent.match(/BlackBerry/i)
|| window.navigator.userAgent.match(/webOS/i)) {
document.body.className += ' mobile';
alert('True - Mobile - ' + navigator.userAgent);
} else {
alert('False - Mobile - ' + navigator.userAgent);
}
if(window.navigator.userAgent.match(/Tablet/i)
|| window.navigator.userAgent.match(/iPad/i)
|| window.navigator.userAgent.match(/Nexus 7/i)
|| window.navigator.userAgent.match(/Nexus 10/i)
|| window.navigator.userAgent.match(/KFAPWI/i)) {
document.body.className -= ' mobile';
document.body.className += ' tablet';
alert('True - Tablet - ' + navigator.userAgent);
} else {
alert('False - Tablet - ' + navigator.userAgent);
}
}
넥서스 7 제조 / 판매하는 안드로이드 태블릿 있을 때 일어나는 UA 구체화하십시오? 첫째, true, true 가 될 수도 있지만, 향후 모바일 되도륵 비해 태블릿 삭제하시겠습니까 바디입니다 태그이고, 모바일 UA 에서 문자열이어야 태블릿
CSS.
body.tablet { background-color: green; }
body.mobile { background-color: red; }
'경고' 개발을 위한 흐름선 덧붙였다. 크롬 콘솔입니다 에뮬레이트합니다 수 많은 휴대용 기기. 테스트 할 수 있다.
EDIT:*
그냥 don& t # 39, 이를 사용하여 특징 탐지 한다. 거기에 너무 많아 장치 및 브랜드를 대상으로 하는 브랜드 배반자들의 오른쪽 solution.* 될 것으로 보인다.
일단 요소점 이득을 전날에약혼자에게 즉시 흐림의 초점을 맞추고 있습니다. 이는 거의 10,000 별들 중 매우 잘 컴포넌트인지 다테피커 부트스트랩에 인기를 얻었고, 깃허브, 는 이 외곽진입:
if (window.navigator.maxTouchPoints || 'ontouchstart' in document) {
this.input.blur();
}
https://github.com/uxsolutions/bootstrap-datepicker
덕분에 [티거] (https://stackoverflow.com/a/36673184) 의 도움을 받는다.
내가 반드시 체크아웃하려고 있습니다 http://wurfl.io/
한마디로 가져올 경우 작은 JS 파일:
<script type='text/javascript' src="//wurfl.io/wurfl.js"></script>
you will be a JSON 객체에는 남겨두고 있는 것처럼 보인다.
{
"complete_device_name":"Google Nexus 7",
"is_mobile":true,
"form_factor":"Tablet"
}
(물론 넥서스 7 을 사용하고 있다고 가정할 때 that& # 39) 와 같은 것들을 할 수 있습니다.
if(WURFL.form_factor == "Tablet"){
//dostuff();
}
이것은 무엇을 찾고 있다.
부인: 이 회사는 이 무료 제공하는 서비스를 위해 일하죠. 감사합니다.
어떤 격자선 " window.screen.width"; ?
if (window.screen.width < 800) {
// do something
}
또는
if($(window).width() < 800) {
//do something
}
이것은 가장 좋은 방법은 매일 새로운 모바일 디바이스 있기 때문에 그런 것 같아요!
최고의 합니다.
var isMobile = (/Mobile/i.test(navigator.userAgent));
하지만 마치 아브 네아 말합니다.
// Seem legit
var isMobile = ('DeviceOrientationEvent' in window || 'orientation' in window);
// But with my Chrome on windows, DeviceOrientationEvent == fct()
if (/Windows NT|Macintosh|Mac OS X|Linux/i.test(navigator.userAgent)) isMobile = false;
// My android have "linux" too
if (/Mobile/i.test(navigator.userAgent)) isMobile = true;
그 후 3 테스트를 아모빌레 바란다 "는 var. 확인