functionGetphonetype () {//Regular, ignoring case varPattern_phone =NewREGEXP ("iphone", "I"); varPattern_android =NewRegExp ("Android", "I"); varUserAgent =navigator.userAgent.toLowerCase (); varIsandroid =pattern_android.test (useragent); varIsiphone =pattern_phone.test (useragent); varPhonetype = "Phonetype"; if(isandroid) {varZh_cnindex = Useragent.indexof ("-"); varSpaceindex = Useragent.indexof ("Build", Zh_cnindex + 4); varFullresult =useragent.substring (Zh_cnindex, Spaceindex); Phonetype= Fullresult.split (";") [1]; } Else if(isiphone) {//6 w=375 6plus w=414 5s w=320 5 w=320 varWigth = 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"; } returnPhonetype; }
JS to determine the current phone model