Simple operating system checking from HTML/JS
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 IIR开发者_如何学GoC.
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).
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
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.
精彩评论