📜  检查浏览器 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:54.045000             🧑  作者: Mango

代码示例1
// Opera 8.0+
var isOpera = (!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0;

// Firefox 1.0+
var isFirefox = typeof InstallTrigger !== 'undefined';

// Safari 3.0+ "[object HTMLElementConstructor]" 
var isSafari = /constructor/i.test(window.HTMLElement) || (function (p) { return p.toString() === "[object SafariRemoteNotification]"; })(!window['safari'] || (typeof safari !== 'undefined' && window['safari'].pushNotification));

// Internet Explorer 6-11
var isIE = /*@cc_on!@*/false || !!document.documentMode;

// Edge 20+
var isEdge = !isIE && !!window.StyleMedia;

// Chrome 1 - 79
var isChrome = !!window.chrome && (!!window.chrome.webstore || !!window.chrome.runtime);

// Edge (based on chromium) detection
var isEdgeChromium = isChrome && (navigator.userAgent.indexOf("Edg") != -1);

// Blink engine detection
var isBlink = (isChrome || isOpera) && !!window.CSS;


var output = 'Detecting browsers by ducktyping:
'; output += 'isFirefox: ' + isFirefox + '
'; output += 'isChrome: ' + isChrome + '
'; output += 'isSafari: ' + isSafari + '
'; output += 'isOpera: ' + isOpera + '
'; output += 'isIE: ' + isIE + '
'; output += 'isEdge: ' + isEdge + '
'; output += 'isEdgeChromium: ' + isEdgeChromium + '
'; output += 'isBlink: ' + isBlink + '
'; document.body.innerHTML = output; Run code snippet