jQuery/Javascript 在没有插件的情况下检测操作系统?
我正在寻找一种方法来检测下载页面的操作系统,使用 jQuery 或 Javascript 来推荐适用于 Mac 和 Windows 的特定文件.我希望在不向我的页面添加另一个插件的情况下做到这一点.
I am looking for a way to detect the OS for a downloads page using jQuery or Javascript to recommend specific files for Mac vs Windows. I was hoping to do it without adding another plugin to my page.
推荐答案
试试:
var os = navigator.platform;
然后根据结果相应地处理 os 变量.
Then handle the os variable accordingly for your result.
您还可以遍历 navigator
对象的每个对象,以帮助您更熟悉这些对象:
You can also loop through each object of the navigator
object to help get you more familiarized with the objects:
<script type="text/javascript">
for(var i in navigator){
console.log(i+"="+navigator[i]+'<br>');
}
</script>
相关文章