[英]Check touch device using javascript
我有一個小功能,可以檢測用戶是否在運行良好的觸摸設備上...
function is_touch_device() {
return (('ontouchstart' in window) || (navigator.MaxTouchPoints > 0) || (navigator.msMaxTouchPoints > 0));
}
if(!is_touch_device()) {
window.location.href = 'index.html';
}
我要添加一個條件,如果設備是ipad,則不要執行重定向。
我試過了...
function is_touch_device() {
var isiPad = navigator.userAgent.match(/iPad/i) != null;
if( !isiPad ){
return (('ontouchstart' in window)
|| (navigator.MaxTouchPoints > 0)
|| (navigator.msMaxTouchPoints > 0));
}
};
if(!is_touch_device()) {
window.location.href = 'index.html';
}
但是它停止了觸摸設備的重定向,實際上所有這些都有什么想法嗎?
不需要功能,請嘗試使用此腳本;
if( /Android|webOS|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
alert('Mobile device, exclude iPad');
}
else {
alert('Desktop');
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.