const browser = ((agent) => {
switch (true) {
case agent.indexOf("edge") > -1: return "edge";
case agent.indexOf("edg") > -1: return "chromium based edge (dev or canary)";
case agent.indexOf("opr") > -1 && !!window.opr: return "opera";
case agent.indexOf("chrome") > -1 && !!window.chrome: return "chrome";
case agent.indexOf("trident") > -1: return "ie";
case agent.indexOf("firefox") > -1: return "firefox";
case agent.indexOf("safari") > -1: return "safari";
default: return "other";
}
}) (window.navigator.userAgent.toLowerCase());
有一个简单的示例如何使用对象navigator.userAgent的属性来检测浏览器Window。有人可以解释一下这段代码的最新一行实际上做了什么以及为什么toLowerCase()这里需要方法?
噜噜哒
相关分类