XPSP2: How To Detect IE6 for SP2


A quick note that’s becoming something of an internal FAQ – the information below is from MSDN.

Detecting Internet Explorer in SP2
You can use window.navigator.userAgent to detect if the browser connecting to your site is Internet Explorer in SP2.
var g_fIsSP2 = false;
function browserVersion()
{
  g_fIsSP2 = (window.navigator.userAgent.indexOf(“SV1”) != -1);
  if (g_fIsSP2)
    {
      //This browser is Internet Explorer in SP2.
    }
  else
    {
      //This browser is not Internet Explorer in SP2.
    }
}

If the user agent string contains “SV1”, the browser connecting to your site is Internet Explorer in SP2.

Pasted from <http://msdn.microsoft.com/security/default.aspx?pull=/library/en-us/dnwxp/html/xpsp2web.asp>

An example SP2 user-agent string looks like this: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)

Comments (15)

  1. Anonymous says:

    IEBlog’s coverage of the user-agent

  2. Jesper Holmberg says:

    Probably entirely beside the point, but what’s "SV1" supposed to be an abbreviation for?

  3. TristanK says:

    Should have anticipated the question; I have no idea!

    Scottish Version 1, perhaps? (I’ll ask around, see if it actually means anything).

  4. Mike Kolitz says:

    Crap! You beat me to it 🙂

  5. TristanK says:

    "Security Version 1" is what I’m told.

    (Though conspiracy theorists might suggest that ten years from now, we’ll be claiming it never stood for anything and trying to release a product with SV Version 2014 in the title)…

  6. Stephane Rodriguez says:

    The act of detecting the client browser goes counter wise the world wide web itself. Vade retro satanas.

  7. TristanK says:

    Why do you think that?

    RFC 2616:

    14.43 User-Agent

    The User-Agent request-header field contains information about the user agent originating the request. This is for statistical purposes, the tracing of protocol violations, and automated recognition of user agents for the sake of tailoring responses to avoid particular user agent limitations. User agents SHOULD include this field with requests.

  8. Raymond Chen says:

    Shouldn’t you also check for IE version greater than 6.0? Or do you not consider IE7 (if it ever exists) to contain IE6SP2?

  9. TristanK says:

    Good point – I personally see this as a short-term "workaround enabler"; it’s probably a good idea to do as you suggest.

    Other possibilities may include:

    – SV1 retained in IE7’s User-Agent

    – SV2 in IE7’s User-Agent

    – MSIE 7.0 only in User-Agent

    But I’d imagine that we’d have similar guidance available for that, if it ever becomes a reality. (NB, I’m not an IE PM, so have no idea, really).

  10. Kai says:

    Wouldn’t it be a good idea to streamline the useragent and strip it of all unnecessary stuff? F.i. these three all stand for an XP SP2 with latest .NET installed. As you see you cannot rely on any of the extra information other than "SV1". So, no use to have that extra stuff in there.

    Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)

    Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)

    Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; Q312461; SV1)

  11. TristanK says:

    I don’t know – I can see reasons for the user-agent tails above, respectively:

    Windows XP SP2

    Windows XP SP2 with .Net Framework 1.1

    Windows XP SP2 with no .Net Framework, but a hotfix important enough to end up in the request headers (!) (MS01-055).

    So, each is useful in its own way in the above example, with the possible exception of the last one – as optional components are added (like the .Net Framework), the User-Agent acts as a hint to the website that certain optional capabilities are available.

    Make sense?

  12. Adamus says:

    I need to have a script which will resize the current window (after loading) depending on if they are running IE6 w/ or w/o SP2. This is what I have written, but it doesn’t appear to work…any ideas?

    <script type="text/javascript" language="javascript">

    var g_fIsSP2 = false;

    function browserVersion()

    {

    g_fIsSP2 = (window.navigator.userAgent.indexOf("SV1") != -1);

    if (g_fIsSP2)

    {

    <!– This browser is Internet Explorer in SP2. –>

    <script type="text/javascript" language="javascript">

    window.resizeto(1024,764);

    </script>

    }

    else

    {

    <!– This browser is not Internet Explorer in SP2. –>

    <script type="text/javascript" language="javascript">

    window.resizeto(1024,734);

    </script>

    }

    }

    </script>

  13. TristanK says:

    Are you calling the browserVersion() function anywhere (like in a page load event)? It looks like you’ve extended the version checking function to also resize the window.

  14. RamireZ says:

    Hi.

    I need to know what I can do to prevent the script on a page, detecting that I have SP2 installed?

  15. TristanK says:

    From IE itself, I don’t believe there’s a lot you can do (other than disabling scripting, which will kill the script).

    If you’re hosting IE (Webbrowser control) in an application, I’ve noticed Avant (and probably Maxthon) adjust the user-agent.

    There’s probably a much simpler way of doing this, but from a quick trawl of MSDN, I’m guessing that you could hack the headers in the BeforeNavigate2 event.

    But for end-users, I don’t think it’s something that can be toggled per se.