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.

3
  • 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. Commented Mar 3, 2011 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? Commented Mar 3, 2011 at 17:54
  • Here are some recent questions you asked that might qualify for accepted-answers : stackoverflow.com/questions/5169022/… stackoverflow.com/questions/5140312/is-boost-ipc-any-good stackoverflow.com/questions/4948121/problems-with-cmake-vars Commented Mar 3, 2011 at 20:14

3 Answers 3

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

Sign up to request clarification or add additional context in comments.

6 Comments

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?
That's what JS is for. I'll post a function in a second.
I've updated the answer, so maybe you could test my function (or remove the regex).
I was just testing something even simpler: if(navigator.platform.substr(0,3).toLowerCase() == "win")
But dues that guarantee that you'll find people only with IE? Firefox, Chrome, etc. works on Windows and still gives the same substring...
|
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 Comment

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: developer.mozilla.org/en/DOM/window.navigator.platform?
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.