The simplest in history, JS and get the phone model

Source: Internet
Author: User

The original version of the Apple series, but the idea of conversion, first to infer whether it is an apple, and then use the resolution to obtain the model


Get Phone model function begin
function Getphonetype () {


Regular, ignoring uppercase and lowercase
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





Phone Touch Event starts

<script>


function Load () {

Document.addeventlistener (' Touchstart ', touch, false);
Document.addeventlistener (' Touchmove ', touch, false);
Document.addeventlistener (' touchend ', touch, false);

function Touch (event) {
var event = Event | | window.event;

var oinp = document.getElementById ("InP");

Switch (event.type) {
Case "Touchstart":
oinp.innerhtml = "Touch started (" + Event.touches[0].clientx + "," + Event.touches[0].clienty + ")";
Break
Case "Touchend":
oinp.innerhtml = "<br>touch End (" + Event.changedtouches[0].clientx + "," + Event.changedtouches[0].clienty + ")";
Break
Case "Touchmove":
Event.preventdefault ();
oinp.innerhtml = "<br>touch moved (" + Event.touches[0].clientx + "," + Event.touches[0].clienty + ")";
Break
}

}
}
Window.addeventlistener (' Load ', load, false);
</script>

Touch Event Ended




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.