【问题标题】:Check touch device using javascript使用 javascript 检查触摸设备
【发布时间】:2014-08-01 10:01:54
【问题描述】:

我有一个小功能可以检测我的用户是否在完美运行的触控设备上...

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';
        }

但它会阻止触摸设备重定向,事实上,所有这些,有什么想法吗?

【问题讨论】:

    标签: javascript jquery ios ipad


    【解决方案1】:

    不需要函数,试试这个脚本;

        if( /Android|webOS|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
            alert('Mobile device, exclude iPad');
        }
        else {
            alert('Desktop');
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-04-27
      • 1970-01-01
      • 2019-03-09
      • 1970-01-01
      • 1970-01-01
      • 2012-09-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多