Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/432.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用jQuery或javascript检测您的设备是iPad3还是iPad4?_Javascript_Jquery_Ios_Ipad 3 - Fatal编程技术网

如何使用jQuery或javascript检测您的设备是iPad3还是iPad4?

如何使用jQuery或javascript检测您的设备是iPad3还是iPad4?,javascript,jquery,ios,ipad-3,Javascript,Jquery,Ios,Ipad 3,我一直在寻找一些方法来检测iPad3和iPad4设备。我正在动态添加元视口。我想查看桌面版本并删除桌面、iPad3和iPad4中的视口,但在mobile中,当然要添加视口以查看移动版本 请检查var ApplyViewPort中的my init函数: var deviceDetection = function () { var osVersion, device, deviceType, userAgent, isSmartphoneOrTablet; device = (nav

我一直在寻找一些方法来检测iPad3iPad4设备。我正在动态添加元视口。我想查看桌面版本并删除桌面iPad3iPad4中的视口,但在mobile中,当然要添加视口以查看移动版本

请检查var ApplyViewPort中的my init函数:

var deviceDetection = function () { 
var osVersion, 
device, 
deviceType, 
userAgent, 
isSmartphoneOrTablet; 

device = (navigator.userAgent).match(/Android|iPhone|iPad|iPod/i); 

if ( /Android/i.test(device) ) { 
    if ( !/mobile/i.test(navigator.userAgent) ) { 
        deviceType = 'tablet'; 
    } else { 
        deviceType = 'phone'; 
    } 

    osVersion = (navigator.userAgent).match(/Android\s+([\d\.]+)/i); 
    osVersion = osVersion[0]; 
    osVersion = osVersion.replace('Android ', ''); 

} else if ( /iPhone/i.test(device) ) { 
    deviceType = 'phone'; 
    osVersion = (navigator.userAgent).match(/OS\s+([\d\_]+)/i); 
    osVersion = osVersion[0]; 
    osVersion = osVersion.replace(/_/g, '.'); 
    osVersion = osVersion.replace('OS ', ''); 

} else if ( /iPad/i.test(device) ) { 
    deviceType = 'tablet';
    osVersion = (navigator.userAgent).match(/OS\s+([\d\_]+)/i); 
    osVersion = osVersion[0]; 
    osVersion = osVersion.replace(/_/g, '.'); 
    osVersion = osVersion.replace('OS ', ''); 
}

isSmartphoneOrTablet = /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent); 
userAgent = navigator.userAgent; 

return { 'isSmartphoneOrTablet': isSmartphoneOrTablet, 
         'device': device, 
         'osVersion': osVersion, 
         'userAgent': userAgent, 
         'deviceType': deviceType
        }; 
}();

var ApplyViewPort = {

    init: function() {
        this.metaView   = '<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />';
        /// Preppend a meta viewport if it's not yet preppended
        /// Else remove the meta viewport
        if (deviceDetection.deviceType == 'tablet') {
            $('meta[name="viewport"]').remove();

            if (window.devicePixelRatio == 2) {
                $('meta[name="viewport"]').remove();
            }

        } else {
            $('head').append(this.metaView);
        }

    }
}

$(document).ready(function() {
    ApplyViewPort.init();

});
var deviceDetection=function(){
变量OSV,
装置,
设备类型,
用户代理,
isSmartphoneOrTablet;
device=(navigator.userAgent).match(/Android | iPhone | iPad | iPod/i);
如果(/Android/i.test(设备)){
如果(!/mobile/i.test(navigator.userAgent)){
deviceType='平板';
}否则{
deviceType='电话';
} 
osVersion=(navigator.userAgent).match(/Android\s+([\d\.]+)/i);
osVersion=osVersion[0];
osVersion=osVersion.replace('Android','');
}如果(/iPhone/i.test(设备)){
deviceType='电话';
osVersion=(navigator.userAgent).match(/OS\s+([\d\\\+)/i);
osVersion=osVersion[0];
osVersion=osVersion.replace(/_/g,'.');
osVersion=osVersion.replace('OS','');
}如果(/iPad/i.test(设备)){
deviceType='平板';
osVersion=(navigator.userAgent).match(/OS\s+([\d\\\+)/i);
osVersion=osVersion[0];
osVersion=osVersion.replace(/_/g,'.');
osVersion=osVersion.replace('OS','');
}
isSmartphoneOrTablet=/Android | webOS | iPhone | iPad | iPod | BlackBerry/i.test(navigator.userAgent);
userAgent=navigator.userAgent;
返回{'isSmartphoneOrTablet':isSmartphoneOrTablet,
“设备”:设备,
“osVersion”:osVersion,
“userAgent”:userAgent,
“deviceType”:deviceType
}; 
}();
var ApplyViewPort={
init:function(){
this.metaView='';
///如果元视口尚未预先绘制,请预先绘制
///否则删除元视口
如果(deviceDetection.deviceType=='tablet'){
$('meta[name=“viewport”]”)。删除();
if(window.devicePixelRatio==2){
$('meta[name=“viewport”]”)。删除();
}
}否则{
$('head').append(this.metaView);
}
}
}
$(文档).ready(函数(){
ApplyViewPort.init();
});

试试这一款,它有device.model;这将为您提供准确的ipad版本,但您只需要使用phonegap更高版本

在ipad 1和2之间进行检测:

  • 检查iPad的UA字符串
  • 检查陀螺仪
  • 在iPad 2和3个步骤之间进行检测:

  • 检查iPad的UA字符串
  • 检查像素密度(视网膜iPad 3显示=2)
  • 在iPad 3和4步骤之间进行检测:

  • 检查iPad的UA字符串
  • 检查像素密度(视网膜显示=2)
  • 检查设备的最大各向异性(iPad 3=2,iPad 4=16)
  • 最大各向异性为16通常表示现代设备具有良好的图形性能

    var-gl;
    var-iPadVersion=false;
    window.ondevicemotion=函数(事件){
    if(!iPadVersion&&navigator.platform.indexOf(“iPad”)!=-1){
    iPadVersion=1;
    if(event.acceleration)iPadVersion=window.devicePixelRatio;
    }
    window.ondevicmotion=null;
    }
    函数initWebGL(画布){
    gl=null;
    试一试{
    gl=canvas.getContext(“webgl”)| canvas.getContext(“实验性webgl”);
    }
    捕获(e){}
    如果(!gl){
    gl=null;
    }
    返回总账;
    }
    函数checkMaxObstrophic(){
    var max=0;
    var canvas=document.getElementById('webGLCanvasTest');
    gl=初始化WebGL(画布);
    试一试{
    gl=canvas.getContext(“webgl”)| canvas.getContext(“实验性webgl”);
    }
    捕获(e){}
    如果(德国劳埃德船级社){
    var ext=(
    gl.getExtension('EXT\u texture\u filter\u各向异性')||
    gl.getExtension('MOZ\u EXT\u texture\u filter\u各向异性')||
    gl.getExtension('WEBKIT\u EXT\u texture\u filter\u各向异性')
    );
    如果(分机){
    max=gl.getParameter(ext.max\u纹理\u max\u各向异性\u ext);
    }
    }
    返回最大值;
    }
    功能isiPad($window){
    var ua=$window.navigator.userAgent | |$window.navigator.vendor | |$window.opera;
    返回(/iPad/)。测试(ua);
    }
    函数getiPadVersion($window){
    if(isiPad(窗口)和&window.devicePixelRatio==2){
    如果(选中max各向异性()<4){
    iPadVersion=3;
    }否则{
    iPadVersion=4;
    }
    }
    返回iPadVersion;
    }
    /*奖金代码
    isSmartDevice()-检测大多数移动设备
    isOldDevice()-检测视频卡性能较差的旧设备
    */
    功能设备($window){
    var ua=$window.navigator.userAgent | |$window.navigator.vendor | |$window.opera;
    返回(/iPhone | iPod | iPad | Silk | Android | BlackBerry | Opera Mini | IEMobile/).test(ua);
    }
    函数isOldDevice(){
    if(isSmartDevice(窗口)和&window.devicePixelRatio==1和&CheckMaxAstrophic()<4 || isiPad(窗口)和&CheckMaxAstrophic()<4){
    返回true;
    }否则{
    返回false;
    }
    }
    警报('iPad版本:'+getiPadVersion(窗口))
    
    #webGLCanvasTest{
    宽度:1px;
    高度:1px;
    位置:固定;
    顶部:-1px;
    左:-1px;
    }
    
    
    dup?我在检测平板电脑时使用window.devicePixelRatio。如果你没有把它放进去。这也会影响手机版的试用,这一款有device.model;这将为您提供准确的ipad版本,但您只需要使用phonegap更高版本下载phonegap或cordova 3.0版本,然后将其包含在html中并开始使用。已查看此文档。但它无法具体检测iPad3和iPad4。感谢您回答如何设置插件?下载phonegap或cordova 3.0版本,然后将其包含在html中并开始使用。下载后,文件保存在何处?因为里面也有很多zip文件。不同cordova设备的文件夹