Browser Identifier - Internet Explorer

Asked

Viewed 2,354 times

1

I need to know when the user accesses the website through Internet Explorer, run a CSS. So far so good, follow the code I used to apply CSS:

 <!--[if IE]>
        <link rel="stylesheet" type="text/css" href="app/template/css/apenas-ie.css" />
 <![endif]-->

However it is not working, unfortunately it is not identifying if it is Internet Explorer or not, because if I apply the css in the standard cover sheet picks, but inside this no.

Does anyone have any Script to check if the browser is Internet Explorer, regardless of the version, so I can then do an if and apply the css? Note: I need this in Javascript.

  • Consider Microsoft Edge also as Internet Explorer?

  • 1

    https://jsfiddle.net/9atsffau/

  • @Sergio only Internet Explorer.

2 answers

2


Done. Follow identification code:

<script type="text/javascript">
var isIE = /*@cc_on!@*/false || !!document.documentMode;
if(isIE == true){
    var ie = ' <link rel="stylesheet" type="text/css" href="app/template/css/apenas-ie.css">';
}else{
     var ie = '';
}
</script>

1

There is your browser detector to understand about @media

Follow the example below:

<link rel="styleSheet" href="./teste-ie.css"/>
<link rel="styleSheet" href="./teste-chrome.css" media="screen and (-webkit-min-device-pixel-ratio:0)" />
<link rel="styleSheet" href="./teste-firefox.css" media="screen and (-moz-images-in-menus:0)" />

or

<style type="text/css">
/* Outros navegadores */
body {
    background: cyan;
}

/* Webkit (Chrome e Safari) */
@media screen and (-webkit-min-device-pixel-ratio:0) { 
    body {
        background: darkseagreen;
    }
}

/* Mozilla Firefox */
@media screen and (-moz-images-in-menus:0) {
    body {
        background: gold;
    }
}
</style>

No rule IE is a default Microsoft leaves no value media or see below: http://browserstrangeness.bitbucket.org/css_hacks.html (there’s another way to see)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.