The simplest in history, JS and get the phone model

Source: Internet
Author: User

Originally can not get the Apple series model, but switch ideas, first determine whether it is Apple, and then use the resolution to obtain the model


Get Phone model function begin
function Getphonetype () {


Regular, ignoring case
var pattern_phone = new RegExp ("iphone", "I");
var pattern_android = new RegExp ("Android", "I");
var useragent = Navigator.userAgent.toLowerCase ();
var isandroid = pattern_android.test (useragent);
var isiphone = pattern_phone.test (useragent);
var phonetype= "Phonetype";
if (isandroid) {
var zh_cnindex = Useragent.indexof ("-");
var spaceindex = useragent.indexof ("Build", zh_cnindex+4);
var fullresult = useragent.substring (Zh_cnindex,spaceindex);
Phonetype=fullresult.split (";") [1];
}else if (isiphone) {
6 w=375 6plus w=414 5s w=320 5 w=320
var wigth = Window.innerwidth | | Document.documentElement.clientWidth | | Document.body.clientWidth;
if (wigth>400) {
Phonetype = "Iphone6 plus";
}else if (wigth>370) {
Phonetype = "Iphone6";
}else if (wigth>315) {
Phonetype = "iphone5 or iphone5s";
}else{
Phonetype = "iphone 4s";
}


}else{
Phonetype = "Your device is too advanced";
}




return phonetype;
}
End

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

The simplest in history, JS and get the phone model

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.