Detect if device is iOS

前端 未结 17 1628
一整个雨季
一整个雨季 2020-11-22 01:39

I\'m wondering if it\'s possible to detect whether a browser is running on iOS, similar to how you can feature detect with Modernizr (although this is obviously device detec

17条回答
  •  失恋的感觉
    2020-11-22 02:18

    I wrote this a couple years ago but i believe it still works:

    if(navigator.vendor != null && navigator.vendor.match(/Apple Computer, Inc./) && navigator.userAgent.match(/iPhone/i) || (navigator.userAgent.match(/iPod/i))) 
    
        {
    
            alert("Ipod or Iphone");
    
        }
    
    else if (navigator.vendor != null && navigator.vendor.match(/Apple Computer, Inc./) && navigator.userAgent.match(/iPad/i))  
    
        {
    
            alert("Ipad");
    
        }
    
    else if (navigator.vendor != null && navigator.vendor.match(/Apple Computer, Inc./) && navigator.userAgent.indexOf('Safari') != -1)
    
        {
    
            alert("Safari");
    
        }
    
    else if (navigator.vendor == null || navigator.vendor != null)
    
        {
    
            alert("Not Apple Based Browser");
    
        }
    

提交回复
热议问题