本文介绍了如何在Javascript中检测Microsoft Chromium Edge(chredge,edgium)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

"Edge 75"将是(是)第一个基于Chromium的Edge浏览器.如何检查此浏览器是否为Chrome上的Edge?

'Edge 75' will be (is?) the first Chromium Based Edge browser. How can I check if this browser is Edge on Chrome ?

(我真正想知道的是,浏览器是否完全支持data-uri的- https://caniuse .com/#feat = datauri -特征检测甚至会更好.如果您知道一种方法,我可以更改问题)

(What I really want to know is if the browser fully supports data-uri's - https://caniuse.com/#feat=datauri - so feature detection would even be better. If you know a way to do that, I can change the question)

推荐答案

您可以使用window.navigator userAgent来检查浏览器是Microsoft Chromium Edge还是Chrome.

You could use the window.navigator userAgent to check whether the browser is Microsoft Chromium Edge or Chrome.

代码如下:

<script>
    var browser = (function (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());
    document.body.innerHTML = window.navigator.userAgent.toLowerCase() + "<br>" + browser;
</script>

Chrome浏览器的userAgent:

The Chrome browser userAgent:

Edge浏览器userAgent:

The Edge browser userAgent:

Microsoft Chromium Edge Dev userAgent:

The Microsoft Chromium Edge Dev userAgent:

Microsoft Chromium Edge Canary userAgent:

The Microsoft Chromium Edge Canary userAgent:

我们可以看到Microsoft Chromium Edge userAgent包含" edg "关键字,我们可以使用它来检测浏览器是Chromium Edge浏览器还是Chrome浏览器.

As we can see that Microsoft Chromium Edge userAgent contains the "edg" keyword, we could use it to detect whether the browser is Chromium Edge browser or Chrome browser.

这篇关于如何在Javascript中检测Microsoft Chromium Edge(chredge,edgium)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 21:38