Get the App
SLTechnology News&Howtos  ›  Development  › 

How does JavaScript determine whether it is a certain type of mobile phone?

Shulou Source: shulou.com Published: 2022-06-01 02:56:31 11月14日 Update

This article will explain in detail how JavaScript judges whether it is a certain type of mobile phone model, Xiaobian thinks it is quite practical, so share it with you as a reference, I hope you can gain something after reading this article.

Whether it is a certain type of mobile phone model//use devicePixelRatio and resolution to judge

const isIphonex = () => {

// X XS, XS Max, XR

const xSeriesConfig = [

{

devicePixelRatio: 3,

width: 375,

height: 812

},

{

devicePixelRatio: 3,

width: 414,

height: 896

},

{

devicePixelRatio: 2,

width: 414,

height: 896

}

];

// h6

if (typeof window !== "undefined" && window) {

const isIOS = /iphone/gi.test(window.navigator.userAgent);

if (! isIOS) return false;

const { devicePixelRatio, screen } = window;

const { width, height } = screen;

return xSeriesConfig.some(

item =>

item.devicePixelRatio === devicePixelRatio &&

item.width === width &&

item.height === height

);

}

return false;

}; About "JavaScript how to judge whether it is a certain type of mobile phone model" This article is shared here, I hope the above content can be of some help to everyone, so that you can learn more knowledge, if you think the article is good, please share it for more people to see.

Tags: Model mobile phone article more good practical content resolution article knowledge reference help related Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Docker Shulou Technology Linux Redmi