How to check if Internet Explorer is smaller than version 10?

1

I need to do a browser check to see if it is Internet Explorer and if it is smaller than version 10.

How to do it?

PS: My idea is to tell the user if you are using a version lower than 10 that downloads a more current browser.

    
asked by anonymous 11.06.2014 / 23:06

2 answers

3

Internet Explorer has a document property that gives this. It is documentMode .

Test this code:

alert(document.documentMode); // dá o numero da versão do IE

link

However, and as the bfavaretto mentioned it is best to rely on feature detection, to detect features, as this is more reliable.

A good example was when version 11 of IE came out they decided to change the UA string and everyone had problems with that.

Here's an interesting link with more alternatives: link

If you want to detect within HTML (without JavaScript necessarily) you can use code comments that only IE detects. For example:

<!--[if lte IE 7]><script>
    ie = 7;
</script><![endif]-->

lte means IE

11.06.2014 / 23:18
2

Another way is to check for some objects and combine some checks.

The following table contains the conditions ready for use.

Versões do IE   Verificar condição
10+             document.all 
9+              document.all &&! ​​Window.atob 
8+              document.all &&! ​​Document.addEventListener 
7+              document.all &&! ​​Document.querySelector 
6+              document.all &&! ​​Window.XMLHttpRequest 
5.x             document.all &&! ​​Document.compatMode

In the following example the condition is true whether the browser is IE11 + or not.

if (!document.all) {
    alert('Voce utiliza o IE11+ ou um outro navegador');
}

Source

>     
11.06.2014 / 23:32