·您当前的位置:首页 > 技术教程 > JavaScript >

[JS]IE浏览器版本如何用js代码检测和识别(ie版本判断)

时间:2017-11-08 16:17酷播
[JS]IE浏览器版本如何用js代码检测和识别

IE11或者非IE

if (!document.all) { alert('IE11+ or not IE'); }

IE10

if (document.all && document.addEventListener && window.atob) { alert('IE10'); }

IE9

if (document.all && document.addEventListener && !window.atob) { alert('IE9'); }

IE8上面已经给出

if (document.all && document.querySelector && !document.addEventListener) { alert('IE8'); }

IE7

if (document.all && window.XMLHttpRequest && !document.querySelector) { alert('IE7'); }

IE6

if (document.all && document.compatMode && !window.XMLHttpRequest) { alert('IE6'); }

检测IE版本

var win = window; var doc = win.document; var input = doc.createElement ("input");  var ie = (function (){ //"!win.ActiveXObject" is evaluated to true in IE11 if (win.ActiveXObject === undefined) return null; if (!win.XMLHttpRequest) return 6; if (!doc.querySelector) return 7; if (!doc.addEventListener) return 8; if (!win.atob) return 9; //"!doc.body.dataset" is faster but the body is null when the DOM is not //ready. Anyway, an input tag needs to be created to check if IE is being //emulated if (!input.dataset) return 10; return 11; })();

热门文章推荐

请稍候...

保利威视云平台-轻松实现点播直播视频应用

酷播云数据统计分析跨平台播放器