Blog du Tristank

So terrific that 3 of 4 readers rated it "soporific"

Blogs

XPSP2: How To Detect IE6 for SP2

  • Comments 16
  • Likes

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
  • Probably entirely beside the point, but what's &quot;SV1&quot; supposed to be an abbreviation for?

  • Should have anticipated the question; I have no idea! <br> <br>Scottish Version 1, perhaps? (I'll ask around, see if it actually means anything).

  • Crap! You beat me to it :)

  • &quot;Security Version 1&quot; is what I'm told. <br>(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)...

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

  • Why do you think that? <br> <br>RFC 2616: <br> <br>14.43 User-Agent <br>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. <br>

  • 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?

  • Good point - I personally see this as a short-term &quot;workaround enabler&quot;; it's probably a good idea to do as you suggest. <br> <br>Other possibilities may include: <br> - SV1 retained in IE7's User-Agent <br> - SV2 in IE7's User-Agent <br> - MSIE 7.0 only in User-Agent <br> <br>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).

  • 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 &quot;SV1&quot;. So, no use to have that extra stuff in there. <br> <br>Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) <br>Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322) <br>Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; Q312461; SV1)

  • I don't know - I can see reasons for the user-agent tails above, respectively: <br> <br>Windows XP SP2 <br>Windows XP SP2 with .Net Framework 1.1 <br>Windows XP SP2 with no .Net Framework, but a hotfix important enough to end up in the request headers (!) (MS01-055). <br> <br>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. <br> <br>Make sense?

  • 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? <br> <br>&lt;script type=&quot;text/javascript&quot; language=&quot;javascript&quot;&gt; <br>var g_fIsSP2 = false; <br>function browserVersion() <br>{ <br> g_fIsSP2 = (window.navigator.userAgent.indexOf(&quot;SV1&quot;) != -1); <br> if (g_fIsSP2) <br> { <br> &lt;!-- This browser is Internet Explorer in SP2. --&gt; <br> &lt;script type=&quot;text/javascript&quot; language=&quot;javascript&quot;&gt; <br> window.resizeto(1024,764); <br> &lt;/script&gt; <br> } <br> else <br> { <br> &lt;!-- This browser is not Internet Explorer in SP2. --&gt; <br> &lt;script type=&quot;text/javascript&quot; language=&quot;javascript&quot;&gt; <br> window.resizeto(1024,734); <br> &lt;/script&gt; <br> } <br>} <br>&lt;/script&gt;

  • 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.

  • IEBlog's coverage of the user-agent

  • Hi. <br>I need to know what I can do to prevent the script on a page, detecting that I have SP2 installed? <br>