简体   繁体   中英

Best way to detect if browser version is less than IE9 using JQuery 1.8+

Before I get chided over this being an old question , I have done my research on it and conditional statements in the HTML seem to be a strict no with IE10+ no longer supporting them and hence any condition statements I write using [if lt IE 9] are not adhered to when using IE10 and above. So in my opinion this method is crossed.

I didn't find any clear answer for if using 1.8+ over the browser with the version and don't want to use raw javascript. I could use modernizer but I just have one line of code to include in the condition and don't want to add in the extra load if that were possible to be implemented using some jquery snippet.

Suggestions?

Ok, so after a little research, decided to use neither JQuery nor modernizer and am utilizing browser capabilities on IE9+ to write conditional code for I8 and below -

<script> 
   if(!document.addEventListener){
       //code for IE8 and below
    }
</script> 

Kind of a hack but it works and fingers crossed :)

Adding more info,

http://tanalin.com/en/articles/ie-version-js/

IE versions Condition to check for

IE 10 or older - document.all
IE 9 or older - document.all && !window.atob
IE 8 or older - document.all && !document.addEventListener
IE 7 or older - document.all && !document.querySelector
IE 6 or older - document.all && !window.XMLHttpRequest
IE 5.x - document.all && !document.compatMode

Hope it helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM