Home Web Front-end JS Tutorial JavaScript – Apple device detection sample code_javascript tips

JavaScript – Apple device detection sample code_javascript tips

May 16, 2016 pm 05:15 PM
apple javascript Detection

Here are some javascript detection codes for detecting iPhone, iPod, and iPad devices.

Copy code The code is as follows:

// 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
);

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Apple\'s \'HomeAccessory\' device revealed to have an A18 chipset among other features Apple\'s \'HomeAccessory\' device revealed to have an A18 chipset among other features Sep 27, 2024 am 09:02 AM

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 Update | Hacker explains how to install Epic Games Store and Fortnite on iPad outside the EU Aug 18, 2024 am 06:34 AM

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 iPhone 16 Pro and iPhone 16 Pro Max official with new cameras, A18 Pro SoC and larger screens Sep 10, 2024 am 06:50 AM

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 iPhone 16 and iPhone 16 Plus launched with 48MP \'Fusion camera\', Camera Control and A18 chip Sep 10, 2024 am 09:30 AM

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 Apple analyst offers new insights into upcoming iPhone 16, iPhone SE 4 and even rumoured iPhone 17 Air releases Aug 12, 2024 pm 10:01 PM

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 iOS 18 beta now supports Adaptive Lighting on Matter smart bulbs Aug 14, 2024 pm 12:48 PM

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 New Apple iPhone 16 design and colours shown in comparison video against iPhone 15 Aug 12, 2024 am 06:59 AM

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 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 Sep 14, 2024 am 06:29 AM

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

See all articles