简体   繁体   中英

How can I tell the difference between an iPhone, iPad and iPod in Javascript?

I can check if the user is using a mobile device, and I can check if the user is using mobile safari. But how I can I check which specific type of mobile iDevice the user is using?

var matchiDevice = new RegExp("i[p|P](hone|ad|od)");
var iDeviceTest = matchiDevice.exec(navigator.userAgent);

if (iDeviceTest != null) {
    var iDevice = iDeviceTest[0];
    alert("You are using a " + iDevice + "!");
}
else 
{
    alert("You are not using an iDevice!");
}

This will tell you whether or not it's an iDevice, and which one.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM