JavaScript determines whether the source of access is a phone or a computer and which browser you use

  • 2020-03-30 00:53:50
  • OfStack

What type of browser is js


 if ( window.sidebar && "object" == typeof( window.sidebar ) && "function" == typeof( window.sidebar.addPanel ) ) //  firefox
{
  }
   else if ( document.all && "object" == typeof( window.external ) )   //  ie
   {
    }

Js is a method to distinguish IE from other browsers and ie6-8.

1, document. All
2,!!!!! Window. The ActiveXObject;

Usage:

If (document. All) {
Alert (" Internet explorer ");
} else {
Alert (" non-internet explorer ");
}

If (!!!!! Window. The ActiveXObject) {
Alert (" Internet explorer ");
} else {
Alert (" non-internet explorer ");
}

Here's how to distinguish between IE6, IE7 and IE8:

Var isIE =!!!!! Window. The ActiveXObject;
Var isIE6 = isIE &&! Window. The XMLHttpRequest;
Var isIE8 = isIE &&!!!!! Document. The documentMode;
Var isIE7 = isIE &&! IsIE6 &&! IsIE8;
If (isIE) {
If (isIE6) {
Alert (" 6 ");
{} else if (isIE8)
Alert (" 8 ");
{} else if (isIE7)
Alert (" 7 ");
}
}

First of all, we made sure that this browser was tested again in the case of IE. If you have any doubts, you can test it.

I'm going to use them directly in the judgment, or you can declare them as variables first. It is said that the document.all method will be added to firefox in the future, so it is recommended to use the second method, which should be safer.


Related articles: