3

I've seen a number of questions about using JS to get detailed information about the OS. But I just want to know if I'm on Windows or not - my browser plugin will initially support Windows only so I don't want to make users pointlessly download a EXE/MSI installer.

I thought you could do some things like this without using JS... I've seen weird conditional HTML to detect IE in old books IIRC.

Mr. Boy
  • 60,845
  • 93
  • 320
  • 589
  • 4
    what 70% is low now? I don't accept answers just to boost my rating and I refuse to pander to people who only answer questions to get points. – Mr. Boy Mar 03 '11 at 17:05
  • no it's the way you mark a question as _answered_. You _vote_ an answer as _helpful_. If you're only answering my questions for points, I'd rather you saved your time. And commenting on my question just to complain when you don't submit an answer yourself makes you seem rather petty. Do you spend your time trawling new questions as some self-appointed policeman? – Mr. Boy Mar 03 '11 at 17:54
  • Here are some recent questions you asked that might qualify for accepted-answers : http://stackoverflow.com/questions/5169022/querying-browser-plugin-existence-version-etc http://stackoverflow.com/questions/5140312/is-boost-ipc-any-good http://stackoverflow.com/questions/4948121/problems-with-cmake-vars – rlb.usa Mar 03 '11 at 20:14

3 Answers3

3

You can create a hidden download link and an alternate stylesheet for your site and switch between them using conditional comments:

<!--[if IE 6]>
<link rel="stylesheet" type="text/css" href="ie.css" />
<![endif]-->

And in that stylesheet, normal browsers see this:

#download
{
  display: none;
}

But within the special ie.css stylesheet, you can make it visible:

#download
{
  display: block !important;
}

If you want to do it all with JavaScript, try this function:

if (navigator.appVersion.indexOf('Win') != -1 && /MSIE (\d+\.\d+);/.test(navigator.userAgent))
{
  var version = new Number(RegExp.$1);

  if (version > 7)
  {
    alert('You are using a compatible browser.');
  }
}

I use Chrome and Linux, so I can't test it (and I'm too lazy to switch user agent strings).

Blender
  • 289,723
  • 53
  • 439
  • 496
  • that weird `[if IE 6]` syntax is what I was thinking of. But isn't that for browser only... how do you determine FireFox on Windows Vs Linux for example? Do you have a good link on these? – Mr. Boy Mar 03 '11 at 17:07
  • That's what JS is for. I'll post a function in a second. – Blender Mar 03 '11 at 17:08
  • I've updated the answer, so maybe you could test my function (or remove the regex). – Blender Mar 03 '11 at 17:19
  • I was just testing something even simpler: `if(navigator.platform.substr(0,3).toLowerCase() == "win")` – Mr. Boy Mar 03 '11 at 17:20
  • But dues that guarantee that you'll find people *only* with IE? Firefox, Chrome, etc. works on Windows and still gives the same substring... – Blender Mar 03 '11 at 18:01
  • @Blender Yes that's the point - if you reread my post you'll see I only care about the platform/OS, not the browser. – Mr. Boy Mar 04 '11 at 12:08
2

Can't you use the navigator.platform to check? so like if (navigator.platform == whatever) it's so and so.

yup: http://www.w3schools.com/jsref/prop_nav_platform.asp

  • 1
    Other than this requires JS (not too big a deal) that page isn't very good because it doesn't tell you what the return values can be. Got a link to a more complete reference? Actually is this comprehensive: https://developer.mozilla.org/en/DOM/window.navigator.platform? – Mr. Boy Mar 03 '11 at 17:08
0

If you're not using javascript, the only thing I can think of is taking advantage of IE Conditional comments, but even then, that will only allow you to include/exclude some javascript or css.

If you really want to know the OS, browser, etc. you could try parsing the user-agent string. It reports on the browser, operating system, and other values, but it isn't reliable (for example, you can forge the string). Quirksmode has a good function to detect the browser and OS.

NT3RP
  • 15,262
  • 9
  • 61
  • 97