• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 545
  • Last Modified:

How to detect if the browser is IE7 or less

Hi, I need to execute a JS code just if the browser is not IE7 or less(any other types include IE8+ the code should be executed), so how to detect if the browser is IE7 or less?
Please help.
0
Abdu_Allah
Asked:
Abdu_Allah
  • 2
1 Solution
 
havj123Commented:
Either use this

function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
  var rv = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}
function checkVersion()
{
  var msg = "You're not using Internet Explorer.";
  var ver = getInternetExplorerVersion();

  if ( ver > -1 )
  {
    if ( ver >= 8.0 )
      msg = "You're using a recent copy of Internet Explorer."
    else
      msg = "You should upgrade your copy of Internet Explorer.";
  }
  alert( msg );
}

---------------------------------------------------------------------------

or use the conditional statement

<!--[if gte IE 8]>
<p>You're using a recent version of Internet Explorer.</p>
<![endif]-->

<!--[if lt IE 7]>
<p>Hm. You should upgrade your copy of Internet Explorer.</p>
<![endif]-->

<![if !IE]>
<p>You're not using Internet Explorer.</p>
<![endif]>
0
 
Michel PlungjanIT ExpertCommented:
I think you will need a combination if you will allow the code to execute in for example IE8 AND FF3

As havj suggested, IE can show you what version it is since IE5
http://msdn.microsoft.com/en-us/library/ms537512%28VS.85%29.aspx

<script type="text/javascript">
var isIE = false;
var isIE8 = false;
</script>
<!--[if IE]>
<script type="text/javascript">
 isIE = true;
 </script>
<!--[if gte IE 8]>
<script type="text/javascript">
 isIE8 = true;
 </script>
<![endif]-->
<script type="text/javascript">
  if (!isIE || isIE8) {
    alert('Either IE8+ or some other browser, or possibly IE<5')
  }
</script>

0
 
Michel PlungjanIT ExpertCommented:
Hmm 75 points and no split?
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now