SoFunction
Updated on 2025-03-01

JavaScript determines whether the access is a mobile phone or a computer, and which browser is used

js determines what type of browser it is

Copy the codeThe code is as follows:

 if ( && "object" == typeof( ) && "function" == typeof( ) ) //  firefox

{
  }
   else if ( && "object" == typeof( ) )   //  ie

   {
    }


js is used to distinguish between IE and other browsers and IE6-8.

1、
2、!!;

How to use it is as follows:

if (){
alert("IE browser");
}else{
alert("non-IE browser");
}

if (!!){
alert("IE browser");
}else{
alert("non-IE browser");
}

Here is the method to distinguish between IE6, IE7, and IE8:

var isIE=!!;
var isIE6=isIE&&!;
var isIE8=isIE&&!!;
var isIE7=isIE&&!isIE6&&!isIE8;
if (isIE){
if (isIE6){
alert(”ie6″);
}else if (isIE8){
alert(”ie8″);
}else if (isIE7){
alert(”ie7″);
}
}

First, we ensure that this browser is IE and has conducted a test. If you have any doubts about this, you can test it.

I'm using it directly here in the judgment, and you can declare them as variables first for use. It is said that Firefox will also add this method in the future, so it is recommended to use the second method, which should be safer.

Use () to distinguish multiple browsers. The code example is as follows:

Copy the codeThe code is as follows:

<coding-1 lang="other">
<script type="text/javascript">
var browser={
versions:function(){
var u = , app = ;
return {
trident: ('Trident') > -1, //IE kernel
presto: ('Presto') > -1, //opera kernel
webKit: ('AppleWebKit') > -1, //Apple, Google Kernel
gecko: ('Gecko') > -1 && ('KHTML') == -1, //Firefox kernel
mobile: !!(/AppleWebKit.*Mobile.*/)||!!(/AppleWebKit/), //Is it a mobile terminal
ios: !!(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios terminal
android: ('Android') > -1 || ('Linux') > -1, //android terminal or uc browser
iPhone: ('iPhone') > -1 || ('Mac') > -1, //Is it an iPhone or QQHD browser
iPad: ('iPad') > -1, //Is it an iPad
webApp: ('Safari') == -1 //Whether the web should be a program, there is no header or bottom
};
}()
}

(" Is it a mobile terminal: "+);
(" ios terminal: "+);
(" android terminal: "+);
(" is iPhone: "+);
(" Whether iPad: "+);
();
</script>
</coding>


Whether it is to judge a PC browser or a mobile browser, JavaScript is judged through the User Agent.