What would be the shortest java-script to return 0 i开发者_如何转开发f not internet explorer, and 6-9 for which version it is?
With jQuery:
!$.browser.msie ? 0 : $.browser.version
Without jQuery:
!navigator.userAgent.match(/MSIE/) ? 0 : parseInt(navigator.userAgent.match(/MSIE (\d+)/))
One option: use IE's conditional comments:
<script>var IEversion</script>
<!--[if IE 8]>
<script>IEversion = 8</script>
<![endif]-->
As above both implied, it all depends on your use and context. In general, I'd say this is the best as it detects regardles of js turned on or off:
<!--[if IE 8]>
<script>IEversion = 8</script> /*stylesheet, script, or whatever in there. */
<![endif]-->
CSS Tricks has the full list and basic overview
The jQuery by Radu if it's depending on jQuery, or another depending on your use. And some frameworks/libraries have a method included, so double check there.
精彩评论