How to Disable JavaScript on browsers running IE6 or Lesser

Web Developers often face requirements to detect the browser type and version and execute some script based on that. If you are not using any JavaScript framework, then here’s how to execute a script only if the Internet Explorer version is greater than 6 (IE6)

Just add this piece of code in between the ‘head’ tags

<head>
<
title>Execute script only if > IE 6</title>

<!--[if gte IE 7]>
<SCRIPT LANGUAGE="Javascript">
alert("You are running Internet Explorer 7 or greater");
</SCRIPT>
<![endif]-->

</head>

This is how Microsoft officially recommends you to detect the browser type and version. As stated in the documentation,

“The downlevel-hidden conditional comment contains hyphens ("--") in the opening and closing tag, similar to the basic HTML Comment. The content is placed inside the comment tags. Because the first four characters and the last three characters of the comment are identical to a basic HTML Comment element, downlevel browsers ignore the HTML content inside the comment block”



Will you give this article a +1 ? Thanks in advance


About The Author

Suprotim Agarwal
Suprotim Agarwal, ASP.NET Architecture MVP (Microsoft Most Valuable Professional) works as an Architect Consultant and provides consultancy on how to design and develop Web applications.

Suprotim is also the founder and primary contributor to DevCurry, DotNetCurry and SQLServerCurry. He is the Editor of a Developer Magazine called DNC Magazine. He has also written two EBooks 51 Recipes using jQuery with ASP.NET Controls. and The Absolutely Awesome jQuery CookBook

Follow him on twitter @suprotimagarwal

No comments: