솔리드로 방법이 있는지 여부를 사용자가 사용하고 있는 모바일 디바이스 탐지합니다 jQuery? Css 를 비슷한 @media 속성용? 이 브라우저는 이동식 장치에 대한 실행하십시오 경우 다른 스크립트입니다 싶다.
내가 찾는 것은 '$ 이브라우저' 기능을 포함한다.
Jquery 를 사용하는 대신 사용할 수 있는 단순한 JavaScript 발견할 수 있다.
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
// some code..
}
Jquery 를 통해 좀 더 쉽게 접근할 수 있는 또는 둘 다 사용할 수 있습니다.
$.browser.device = (/android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini/i.test(navigator.userAgent.toLowerCase()));
'지금', '모든' $ 이브라우저 반환되므로 device" 그들위에 디바이스에는 ".
참고: '에서' $ 이브라우저 제거되었으면 [ jQuery v1.9.1] [1]. 그러나 jQuery 마이그레이션과 플러그인에는 사용하여 이를 사용할 수 있습니다. 코드의
보다 완전한 버전:
var isMobile = false; //initiate as false
// device detection
if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|ipad|iris|kindle|Android|Silk|lge |maemo|midp|mmp|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|phone)|xda|xiino/i.test(navigator.userAgent)
|| /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(navigator.userAgent.substr(0,4))) {
isMobile = true;
}
[1]: # jquery 있지만브라우저에 재거됨 http://jquery.com/upgrade-guide/1.9/
Css 에서 파일:
/* Smartphones ----------- */
@media only screen and (max-width: 760px) {
#some-element { display: none; }
}
Jquery 의 / 자바스크립트 파일:
$( document ).ready(function() {
var is_mobile = false;
if( $('#some-element').css('display')=='none') {
is_mobile = true;
}
// now i can use is_mobile to run javascript conditionally
if (is_mobile == true) {
//Conditional script here
}
});
내 사이트 내 목표였던 " friendly", 모바일, 가질 수 있다. 그래서 CSS 를 사용하여 미디어 쿼리합니다 숨기거나 요소를 못하며창조된 따라 화면 크기.
예를 들어, 내가 내 don& # 39 와 같은 모바일 버전을 싶지 않다, 그 모든 이미지 및 관련 물건이요 로드되는지 https://xxx. 활성화하십시오 때문에 페이스북 프로필 # 39 의 좋지 않은 that& 및 모바일 있다. 그래서, 난 또 이렇게 코드 블록 안에 숨어 있는 목동들과 컨테이너입니다 요소를 포함한다 (위).
if(!is_mobile) {
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/pt_PT/all.js#xfbml=1&appId=210731252294735";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
}
이를 볼 수 있습니다 (http://lisboaautentica.com) 의 실천
Javascript API 미디어 감지하는 기능이 내장되어 있다. 위의 솔루션을 사용하는 대신 사용하여 간단히 다음과 같습니다.
$( document ).ready(function() {
var isMobile = window.matchMedia("only screen and (max-width: 760px)").matches;
if (isMobile) {
//Conditional script here
}
});
이 방법을 수 있는 것이 아니라, 짧아진 간단해진다는 it& # 39 의 조건부 수 있지만 다른 장치여야 공략하십시오 등 모든 요소를 필요할 경우 별도로 추가하지 않고도 스마트폰 및 태블릿 pc 더미 DOM.
따르면 mizilla - 브라우저 감지 name. domain. 사용자 에이전트: >. 요약하자면, 사용자 에이전트 문자열을 찾는 것이 좋습니다 "Mobi" 어느 곳에서나 발견할 수 있는 모바일 장치.
다음과 같습니다.
if (/Mobi/.test(navigator.userAgent)) {
// mobile!
}
이렇게 하면 모든 일반적인 일치시킵니다, 오페라, 구글 크롬, 사파리, IE 모바일 브라우저 등 모바일 mizilla 사용자 에이전트, etc.
안드로이드 사용자 에이전트는 에리클 대한 테스트 '는' 으로 보고 있다. [크롬 사용자 에이전트 문자열을], [2] 의 태블릿 Mobi" " 포함되어 있지 않습니다. (그러나 실행하십시오 전화인가 버전).
if (/Mobi|Android/i.test(navigator.userAgent)) {
// mobile!
}
[2]: https://developer.chrome.com/multidevice/user-agent # chrome_for_android_user_agent
단순하고 효과적인 한 줄 광고문:
function isMobile() { return ('ontouchstart' in document.documentElement); }
그러나, 코드 doesn& # 39 위 사례의 laptops 터치스크린 기능과 고려하지 않는다. 따라서 나는 이 두 번째 버전을 기반으로 제공하십시오 @Julian 솔루션이므로:
function isMobile() {
try{ document.createEvent("TouchEvent"); return true; }
catch(e){ return false; }
}
하지만 난 이걸 찾을 수 없는 it& # 39 을 포함한다. http://detectmobilebrowser.com/
이를 통해 모바일 브라우저 자바스크립트 여러 언어로, 이 중 하나는 스크립트에만 발견할 수 있다. # 39 you& 도울 수 있는 것을 통해, re 찾고 있습니다.
그러나 jQuery 를 사용하고 있기 때문에 이 이케리자주포트 취합은 인식해야 할 수 있습니다. # 39 의 집합으로 속성을이 it& 감지할 수 있는 기능을 현재 브라우저. 이 문서는. http://api.jquery.com/jQuery.support/
하도 하는 것이 무엇인지 정확히 알고 don& # 39, t, t know I don& you& # 39, # 39, 이 중 어떤 일을 하게 될 때 유용합니다.
모든 것이 있다는 것, 내가 생각하는 가장 적합한 베팅 인컨텍스트 리디렉션할 또는 다른 스크립트입니다 출력물에는 쓰기 사용하여 서버측 언어 (만약 이것이 오버클로킹된 옵션인지. 이후, x, t 모바일 브라우저 don& 정말로 알고 있습니다 # 39 의 기능을 수행하는 논리 변경 감지, 서버 측에서 약간만이라도 가장 신뢰할 수 있는 방법입니다. 물론 그 모든 는 언어를 사용하여 서버측 can& 경우 # 39 점, 논쟁의 여지가 없다.)
가끔 필요한 것은 알 수 있는 장치를 위해 해당 내용을 보여 주는 장치, 브랜드 클라이언트여야 사용하고 있는 아이폰 저장소나 https://partner. microsoft. 같은 안드로이드 있다. 단, 브라우저 기능, HTML5, 또는 플래시 등 훌륭한 모더 나이저 있습니다.
내 jQuery 의 다른 클래스에 슬라이드에서는 우저지나 솔루션이므로 표시하십시오 디바이스마다 유형:
/*** sniff the UA of the client and show hidden div's for that device ***/
var customizeForDevice = function(){
var ua = navigator.userAgent;
var checker = {
iphone: ua.match(/(iPhone|iPod|iPad)/),
blackberry: ua.match(/BlackBerry/),
android: ua.match(/Android/)
};
if (checker.android){
$('.android-only').show();
}
else if (checker.iphone){
$('.idevice-only').show();
}
else if (checker.blackberry){
$('.berry-only').show();
}
else {
$('.unknown-device').show();
}
}
이 솔루션은 그래픽에서 마니아 http://graphicmaniacs.com/note/detecting-iphone-ipod-ipad-android-and-blackberry-browser-with-javascript-and-php/
해결책을 찾을 수 있는. http://www.abeautifulsite.net/blog/2011/11/detecting-mobile-devices-with-javascript/.
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);
},
any: function() {
return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
}
};
그 후 사용 여부를 확인하려면 모바일 테스트할 수 있습니다.
if(isMobile.any()) {
//some code...
}
만약 " 의해 mobile"; 그러니까 " 작은 화면, "; 내가 이:
var windowWidth = window.screen.width < window.outerWidth ?
window.screen.width : window.outerWidth;
var mobile = windowWidth < 500;
모더나이저 사용하는 경우, 이것은 앞서 언급한 것처럼 '' 모데니즈리투치 매우 쉽게 사용할 수 있습니다.
하지만, 제가 조합하여 사용자 에이전트 테스트, 그냥 '와' 모데니즈리투치 포지셔닝하십시오 스크램블된 금고에도요
var deviceAgent = navigator.userAgent.toLowerCase();
var isTouchDevice = Modernizr.touch ||
(deviceAgent.match(/(iphone|ipod|ipad)/) ||
deviceAgent.match(/(android)/) ||
deviceAgent.match(/(iemobile)/) ||
deviceAgent.match(/iphone/i) ||
deviceAgent.match(/ipad/i) ||
deviceAgent.match(/ipod/i) ||
deviceAgent.match(/blackberry/i) ||
deviceAgent.match(/bada/i));
if (isTouchDevice) {
//Do something touchy
} else {
//Can't touch this
}
또한 사용자 에이전트 '테스트' 부여하느뇨 리모빌레 감지함 마이크로소프트 모바일 디바이스 '윈도폰' 보다 광범위한 있습니다.
우리는 단순히 ',' (http://my.clockodo.com) 에서 사용되는 소형 기기의 스크린스위드스 감지할 수 있습니다. # 39 에 버그가 스테린드와이트하드 there& 죄송합니다. 일부 안드로이드 버전을 함께 이 방법으로 우저지나 결합할 수 있습니다.
if(screen.width < 500 ||
navigator.userAgent.match(/Android/i) ||
navigator.userAgent.match(/webOS/i) ||
navigator.userAgent.match(/iPhone/i) ||
navigator.userAgent.match(/iPod/i)) {
alert("This is a mobile device");
}
이 질문에 답을 많이 있지만, 내가 본 그러니까말이야 뭐로부터요 아니예 외곽진입하는 오토메이티드 the way I 이 문제를 해결할 수 있을 것 "이라고 말했다.
CSS 는 웹 문서 바시드 너버 (미디어 쿼리합니다) 에서 확인할 수 있는 스타일이 적용된 너비입니다. 너비 (javascript 를 사용하지 않는 이유는?
예를 들어 있는 Bootstrap& # 39, s (Mobile First), 미디어 쿼리합니다 좁히어 타임코드가 4 스냅되지 / break 방향점:
이 문제를 해결할 수 있습니다 또한 우리의 JavaScript 로 잘 알려져 있다.
먼저 얻을 수 있는 값을 반환하는 함수를 만들 수 있게 하는 창의 크기와 규모에 지켜보리니 디바이스: 보기 lionbridge 응용 프로그램:
var getBrowserWidth = function(){
if(window.innerWidth < 768){
// Extra Small Device
return "xs";
} else if(window.innerWidth < 991){
// Small Device
return "sm"
} else if(window.innerWidth < 1199){
// Medium Device
return "md"
} else {
// Large Device
return "lg"
}
};
지금까지 우리는 이 값을 저장하는 기능 설정, ans 호출할 수 있습니다.
var device = getBrowserWidth();
당시 질문
>. 이 브라우저는 이동식 장치에 대한 실행하십시오 경우 다른 스크립트입니다 싶다.
지금까지 남아 있는 디바이스 정보가 모두 백업이었습니다 if 문의:
if(device === "xs"){
// Enter your script for handheld devices here
}
고데펜 대한 예를 들어보겠습니다. http://codepen.io/jacob-king/pen/jWEeWG
나는 더 없는 좋은 사이트 지적했다. http://detectmobilebrowsers.com/ 이 템플릿에는 준비됐어들 브라운아저씨의 모바일용 서로 다른 언어로 코드를 탐지 (이에 제한되지 않는):
뿐만 아니라, 그냥 확인 및 할 경우 안에는 탐지합니다 섹선에서 대한 자세한 RegEx 매개변수입니다.
>. 안드로이드 태블릿, 아이패드요, 화재, 킨들 playbook 을 통해 검색되지 않습니다 >. 디자인. 안드로이드 태블릿 pc '아이패드' 를 위한 추가 지원을 추가할 실크, 플레이북 >. 첫 번째 정규 표현식.
내가 사용하는 스토리지 제어할 수 있는 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
mobile = ['iphone','ipad','android','blackberry','nokia','opera mini','windows mobile','windows phone','iemobile','tablet','mobi'];
var ua=navigator.userAgent.toLowerCase();
for (var i in mobile) if (ua.indexOf(mobile[i]) > -1) return true;
// nothing found.. assume desktop
return false;
}
내가 반드시 체크아웃하려고 있습니다 http://wurfl.io/
간단히 말해서, 작은 JavaScript 파일을 가져오면.
<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.is_mobile) {
//dostuff();
}
이것은 무엇을 찾고 있다.
부인: 이 회사는 이 무료 제공하는 서비스를 위해 일하죠.
좋은 답변 감사합니다. 윈도우 폰 지원할 수 있는 작은 개선 및 준.
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/) ||
navigator.userAgent.match(/Windows Phone/i) ||
navigator.userAgent.match(/ZuneWP7/i)
) {
// some code
self.location = "top.htm";
}
이 후, 이를 통해 체크아웃합니다 정말 잘 때 어떻게 해야 할 경우 또는 코드 스니핏 뭐하러요 터치 디바이스 감지되는지 트루히슈타르트 이벤트 호출됨:
$(function(){
if(window.Touch) {
touch_detect.auto_detected();
} else {
document.ontouchstart = touch_detect.surface;
}
}); // End loaded jQuery
var touch_detect = {
auto_detected: function(event){
/* add everything you want to do onLoad here (eg. activating hover controls) */
alert('this was auto detected');
activateTouchArea();
},
surface: function(event){
/* add everything you want to do ontouchstart here (eg. drag & drop) - you can fire this in both places */
alert('this was detected by touching');
activateTouchArea();
}
}; // touch_detect
function activateTouchArea(){
/* make sure our screen doesn't scroll when we move the "touchable area" */
var element = document.getElementById('element_id');
element.addEventListener("touchstart", touchStart, false);
}
function touchStart(event) {
/* modularize preventing the default behavior so we can use it again */
event.preventDefault();
}
그냥 확인 ',' t # 39 isn& 나비가토리우스라그랑 경우 항상 신뢰할 수 있는 것으로 나타났다. 또한 검사를 통해 보다 높은 신뢰성을 달성할 수 있는 '나비개머리판포름'. 이전 작업이 보다 간단한 오토메이티드 수정한 것으로 보인다.
if (/Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent) ||
(/Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.platform))) {
// some code...
}