JavaScript – Apple device detection sample code_javascript tips
May 16, 2016 pm 05:15 PMHere are some javascript detection codes for detecting iPhone, iPod, and iPad devices.
// Apple detection object
var Apple = { };
Apple.UA = navigator.userAgent;
Apple.Device = false;
Apple.Types = ["iPhone", "iPod", "iPad"];
for (var d = 0; d < Apple.Types.length; d ) {
var t = Apple.Types[d];
Apple[t] = !!Apple.UA.match (new RegExp(t, “i”));
Apple.Device = Apple.Device || Apple[t];
}
// is this an Apple device?
alert(
“Apple device? ” Apple.Device
“
iPhone? ” Apple.iPhone
“
iPod? ” Apple.iPod
“
iPad? ” Apple.iPad
);

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Apple\'s \'HomeAccessory\' device revealed to have an A18 chipset among other features

Update | Hacker explains how to install Epic Games Store and Fortnite on iPad outside the EU

iPhone 16 Pro and iPhone 16 Pro Max official with new cameras, A18 Pro SoC and larger screens

Apple iPhone 16 and iPhone 16 Plus launched with 48MP \'Fusion camera\', Camera Control and A18 chip

Apple analyst offers new insights into upcoming iPhone 16, iPhone SE 4 and even rumoured iPhone 17 Air releases

iOS 18 beta now supports Adaptive Lighting on Matter smart bulbs

New Apple iPhone 16 design and colours shown in comparison video against iPhone 15

iPhone parts Activation Lock spotted in iOS 18 RC — may be Apple\'s latest blow to right to repair sold under the guise of user protection
