IE version detection in Javascript

Detection of theĀ  newer versions of IE is much more messy than before. Since IE uses the Trident rendering engine, each IE version uses a particular Trident version, which is what the sample script below does.

 

<html>
<head>
<script>
	function showInfo() {
		var nav= (navigator.userAgent);
		if (nav.indexOf("Trident/7.0") > -1) {
			alert("IE 11.0");
		}
		else if (nav.indexOf("Trident/6.0") > -1) {
			alert("IE 10.0");
		}
		else if (nav.indexOf("Trident/5.0") > -1) {
			alert("IE 9.0");
		}
		else if (nav.indexOf("Trident/4.0") > -1) {
			alert("IE 8.0");
		}
		else
			alert("IE is older than 8.0");
	
	}
	


</script>
</head>
<body>
	<br>
	<a href="#" onclick="showInfo();">Show Info</a>
</body>
</html>

Be the first to comment

Leave a Reply

Your email address will not be published.


*