How to target Edge browser and apply a differet css file

How to target Edge browser and apply a differet css file
0

#1

The following code is an external javascript file which applies different external css files to different browsers.

var nAgt = navigator.userAgent;
var browserName = navigator.appName;
var nameOffset,verOffset,ix;

// In Opera, the true version is after “Opera” or after “Version”
if ((verOffset=nAgt.indexOf(“Opera”))!=-1) {
browserName = “Opera”;
}
// In MSIE, the true version is after “MSIE” in userAgent
else if ((verOffset=nAgt.indexOf(“MSIE”))!=-1) {
browserName = “Microsoft Internet Explorer”;
}
// In Chrome, the true version is after “Chrome”
else if ((verOffset=nAgt.indexOf(“Chrome”))!=-1) {
browserName = “Chrome”;
}
// In Safari, the true version is after “Safari” or after “Version”
else if ((verOffset=nAgt.indexOf(“Safari”))!=-1) {
browserName = “Safari”;
}
// In Firefox, the true version is after “Firefox”
else if ((verOffset=nAgt.indexOf(“Firefox”))!=-1) {
browserName = “Firefox”;
}
// In most other browsers, “name/version” is at the end of userAgent
else if ( (nameOffset=nAgt.lastIndexOf(’ ‘)+1) <
(verOffset=nAgt.lastIndexOf(’/’)) )
{
browserName = nAgt.substring(nameOffset,verOffset);
fullVersion = nAgt.substring(verOffset+1);
if (browserName.toLowerCase()==browserName.toUpperCase()) {
browserName = navigator.appName;
}
}

if (browserName == “Microsoft Internet Explorer”) {
document.write("<link type=“text/css” rel=“stylesheet” href=“IE.css”>");
}
else if (browserName == “Firefox”) {
document.write("<link type=“text/css” rel=“stylesheet” href=“Firefox.css”>");
}
else if (browserName == “Safari”){
document.write("<link type=“text/css” rel=“stylesheet” href=“Safari.css”>");
}
else {
document.write("<link type=“text/css” rel=“stylesheet” href=“Chrome.css”>");
}

I also have an internal javascript code wrapped in script tags that has the following code:

// Browser Detection for Internet Explorer 11 and Avant
ua = window.navigator.userAgent;
if (ua.indexOf(“Trident/7.0”) > 0) {
document.write("<link type=“text/css” rel=“stylesheet” href=“IE.css”>");
}

IE browser detection from the external javascript file did not work for IE 11 because the detection only applies to IE version 10 and below, so I have to write a separate script just for IE 11. It also used to detect Avant browser.

Both script (internal and external) seem to work well except for Microsoft Edge. I don’t know how to write a javascript code just to target Edge browser and apply a different css file accordingly. Any help would be appreciated. Thanks.