浏览器+移动端 js 判断

本文提供了一系列用于检测浏览器类型及支持特性的JavaScript代码片段,包括但不限于Opera、苹果、谷歌等内核的识别,触屏、SVG等特性的支持情况。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

//是否为opera内核
IS_OT: 0 > navigator.userAgent.indexOf("Presto/2.4.") && 0 > navigator.userAgent.indexOf("Presto/2.3.") && 0 > navigator.userAgent.indexOf("Presto/2.2.") && 0 > navigator.userAgent.indexOf("Presto/2.1.") && 0 > navigator.userAgent.indexOf("Presto/2.0.") && 0 > navigator.userAgent.indexOf("Presto/1.");
//是否为苹果、谷歌内核
IS_SF: 0 <= navigator.userAgent.indexOf("AppleWebKit/") && 0 > navigator.userAgent.indexOf("Chrome/");
//是否支持ontouchstart相关的事件
IS_TOUCH: "ontouchstart" in document.documentElement,
//是否支持MSPointer相关的事件
IS_POINTER: null != window.navigator.msPointerEnabled ? window.navigator.msPointerEnabled : !1,


//是否为ie
IS_IE: 0 <= navigator.userAgent.indexOf("MSIE");
//是否为ie6
IS_IE6: 0 <= navigator.userAgent.indexOf("MSIE 6");
//是否为ie11
IS_IE11: !! navigator.userAgent.match(/Trident\/7\./);
//是否为怪异模式
IS_QUIRKS: 0 <= navigator.userAgent.indexOf("MSIE") && (null == document.documentMode || 5 == document.documentMode);(浏览器怪异模式)

IS_NS: 0 <= navigator.userAgent.indexOf("Mozilla/") && 0 > navigator.userAgent.indexOf("MSIE");
//是否为Opera
IS_OP: 0 <= navigator.userAgent.indexOf("Opera/");

//是否为iso
IS_IOS: navigator.userAgent.match(/(iPad|iPhone|iPod)/g) ? !0 : !1;
//是否为Chrome
IS_GC: 0 <= navigator.userAgent.indexOf("Chrome/");
//是否为Firefox
IS_FF: 0 <= navigator.userAgent.indexOf("Firefox/");
IS_MT: 0 <= navigator.userAgent.indexOf("Firefox/") && 0 > navigator.userAgent.indexOf("Firefox/1.") && 0 > navigator.userAgent.indexOf("Firefox/2.") || 0 <= navigator.userAgent.indexOf("Iceweasel/") && 0 > navigator.userAgent.indexOf("Iceweasel/1.") && 0 > navigator.userAgent.indexOf("Iceweasel/2.") || 0 <= navigator.userAgent.indexOf("SeaMonkey/") && 0 > navigator.userAgent.indexOf("SeaMonkey/1.") || 0 <= navigator.userAgent.indexOf("Iceape/") && 0 > navigator.userAgent.indexOf("Iceape/1.");
//是否支持svg
IS_SVG: 0 <= navigator.userAgent.indexOf("Firefox/") || 0 <= navigator.userAgent.indexOf("Iceweasel/") || 0 <= navigator.userAgent.indexOf("Seamonkey/") || 0 <= navigator.userAgent.indexOf("Iceape/") || 0 <= navigator.userAgent.indexOf("Galeon/") || 0 <= navigator.userAgent.indexOf("Epiphany/") || 0 <= navigator.userAgent.indexOf("AppleWebKit/") || 0 <= navigator.userAgent.indexOf("Gecko/") || 0 <= navigator.userAgent.indexOf("Opera/") || null != document.documentMode && 9 <= document.documentMode;
//是否支持foreignObject
NO_FO: !document.createElementNS || "[object SVGForeignObjectElement]" != document.createElementNS("http://www.w3.org/2000/svg", "foreignObject") || 0 <= navigator.userAgent.indexOf("Opera/");
//是否为ie浏览器
IS_VML: "MICROSOFT INTERNET EXPLORER" == navigator.appName.toUpperCase();
//是否为Win
IS_WIN: 0 < navigator.appVersion.indexOf("Win");
//是否为Mac
IS_MAC: 0 < navigator.appVersion.indexOf("Mac");
//是否为本地地址
IS_LOCAL: 0 > document.location.href.indexOf("http://") && 0 > document.location.href.indexOf("https://");

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值