navigator.userAgent.toLowerCase () determines the type of client

Navigator object contains information about the browser.
userAgent is a read-only string, declared value of the browser for the user agent header of the HTTP request. In fact, the role is to return the current user is using what browser.
toLowerCase () converted to lowercase.

To determine whether the client is a pc

isPc: function () {
let userAgentInfo = navigator.userAgent.toLowerCase();
let Agents = new Array("android", "iphone", "symbianOS", "windows phone", "ipad", "ipod");
let flag = true;
for (let v = 0; v < Agents.length; v++) {
if (userAgentInfo.indexOf(Agents[v]) > 0) { flag = false; break; }
}
return flag;
} 

If the pc execute the following code ...

var isPc = user.isPc();
if (isPc) {

} else {

}

 

Guess you like

Origin www.cnblogs.com/una77/p/11199892.html