<! DOCTYPE html>@mediascreen and (-webkit-min-device-pixel-ratio:0) { . box{ Height: 100px; width:100px; Background-color:red; } } </style> JS Recognition"1" Capability detection
"Supplemental 1" using JS capability detection considerations to detect sort sorting as an example
function issortable (object) { return !! Object.sort;}
The above function determines whether an object supports sorting by detecting whether the object has a sort () method. But the problem is that any object that contains the Sort property also returns true
var result = Issortable ({sort:true});
A better way to detect if a property exists and not to determine whether the object supports sorting is to detect if sort is a function
function issortable (object) { returntypeof Object.sort = = "function"; } // The typeof operator above is used to determine that sort is indeed a function, so it can be called to sort the data
"Supplement 2"
[BUG] in IE, typeof Xhr.open will return "Unkown"
if (window. ActiveXObject) { varnew ActiveXObject ("Microsoft.XMLHTTP"); Alert (typeof xhr.open) }
[resolution] in the browser environment to test any object of an attribute exists using the following function
function Ishostmethod (object,property) { vartypeof Object[property]; return t = = "function" | | (!! (t = = "Object" && Object[property])) || t== "Unknown";}
[1] ie8-(document.createelement)
The host object of ie8-is implemented through COM, not JScript. Therefore, the document.createelement () function is indeed a COM object, so typeof returns "Object"
if (typeof document.createelement = = "Object") { alert (1) }
[2] ie10-(document.all)
if (document.all) { alert (1) }
[3] ie10-(ActiveXObject)
if (window. ActiveXObject) { alert (1) }
[4]chrome, Opera (chrome)
if (window.chrome) { alert (1) }
"2" useragent
[1] Ie
functionIsie () {varUA =navigator.useragent; //Detection Trident engine, ie8+ if(/trident/. Test (UA)) { //ie11+ if(/RV: (\d+)/. Test (UA)) { returnregexp["$"]; } //Ie8-ie10 if(/msie (\d+)/. Test (UA)) { returnregexp["$"]; } } //detect IE logo, ie7- if(/msie (\d+)/. Test (UA)) { returnregexp["$"]; }}console.log (Isie ());//only IE returns the version number, and the other browsers return undefined[2]chrome
function Ischrome () { var ua = navigator.useragent; // Get rid of opera first, because opera only adds its own logo after Chrome's useragent. if (!/opr/. Test (UA)) { if(/chrome\/(\s+)/. Test (UA)) { return regexp["$"];}} } Console.log (Ischrome ()); // only Chrome Returns the version number, and all other browsers return undefined
[3]safari
functionIssafari () {varUA =navigator.useragent; //First rule out opera . if(!/opr/. Test (UA)) { //check out Chrome and Safari browser if(/safari/. Test (UA)) { //Detect Safari if(/version\/(\s+)/. Test (UA)) { returnregexp["$"]; }}}}console.log (Issafari ());//only Safari Returns the version number, and all other browsers return undefined[4]firefox
function Isfirefox () { if(/firefox\/(\s+)/. Test (navigator.useragent)) { return regexp["$"]; } } Console.log (Isfirefox ()); // only Firefox will return the version number and other browsers will return undefined
[5]opera
function Isopera () { var ua = navigator.useragent; if (/opr\/(\s+)/. Test (UA)) { return regexp["$"]; } } Console.log (Isopera ()); // only Opera returns the version number, and all other browsers return undefined
Browser-compatible processing (HTML conditional annotations, Csshack, and JS recognition)