How to target Edge browser with javascript

后端 未结 9 742
無奈伤痛
無奈伤痛 2020-12-05 09:26

I know you should do feature detection where possible, but can you detect in Javascript if the browser is the Microsoft Edge browser?

I maintain an old product and I

9条回答
  •  时光说笑
    2020-12-05 09:59

    Browser checks using javascript

    IsChrome: window.navigator.userAgent.indexOf("Chrome") > -1;

    IsIE: window.navigator.userAgent.indexOf("MSIE ") > -1 || !!navigator.userAgent.match(/Trident.*rv\:11\./);

    IsEdge: window.navigator.userAgent.indexOf("Edge/") > -1;

    IsSafari: window.navigator.userAgent.indexOf("Safari") > -1 && window.navigator.userAgent.indexOf('Chrome') == -1;

    IsFirefox: window.navigator.userAgent.indexOf("Firefox") > -1;

    IsChromiumEdge: window.navigator.userAgent.indexOf("Edg/") > -1; // for new edge chromium

提交回复
热议问题