logo

Javascript detect IE

logo

When you have written a few different pieces of JavaScript you come to realize that IE and Firefox have different opinions on what works and what doesn’t work. What this means is you may need to have different JavaScript firing if the current browser is IE! Here is a little example of how we can detect if the current browser is IE:

<script type="text/javascript">
   //we start off by saying the current browser isn’t IE
   var ie = false;
</script>

<!–[if IE]>
<script type="text/javascript">
  //add a conditional comment block that only is run if the browser is IE
   ie = true;
</script>
<![endif]–>

<script type="text/javascript">

//combine with jQuery if needed
               
$(document).ready(function(){
   if(!ie){
      alert("Not an IE browser");
   }else{
      alert("IE browser");
   }
});
</script>

And there you have it, you can now target IE with JavaScript in 3 easy steps!

Leave a Reply

logo
logo
Powered by Wordpress | Designed by Elegant Themes