{"action":"opened","issue":{"url":"https://api.github.com/repos/proYang/outils/issues/15","repository_url":"https://api.github.com/repos/proYang/outils","labels_url":"https://api.github.com/repos/proYang/outils/issues/15/labels{/name}","comments_url":"https://api.github.com/repos/proYang/outils/issues/15/comments","events_url":"https://api.github.com/repos/proYang/outils/issues/15/events","html_url":"https://github.com/proYang/outils/issues/15","id":280672479,"number":15,"title":"关于getOS()返回系统类型不正确","user":{"login":"Alienover","id":12182069,"avatar_url":"https://avatars1.githubusercontent.com/u/12182069?v=4","gravatar_id":"","url":"https://api.github.com/users/Alienover","html_url":"https://github.com/Alienover","followers_url":"https://api.github.com/users/Alienover/followers","following_url":"https://api.github.com/users/Alienover/following{/other_user}","gists_url":"https://api.github.com/users/Alienover/gists{/gist_id}","starred_url":"https://api.github.com/users/Alienover/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Alienover/subscriptions","organizations_url":"https://api.github.com/users/Alienover/orgs","repos_url":"https://api.github.com/users/Alienover/repos","events_url":"https://api.github.com/users/Alienover/events{/privacy}","received_events_url":"https://api.github.com/users/Alienover/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-12-09T03:32:21Z","updated_at":"2017-12-09T03:32:21Z","closed_at":null,"author_association":"NONE","body":"我测试了一下,如果把返回**pc端**的语句放在返回**移动端**的语句前面,这样无论是在**pc端**还是**移动端**,这样都只会返回**pc端**的类型,因此需要把**移动端**的返回语句**提前**,这样,先检查**移动端**类型后,再检查**pc端**的类型,这样比较准确,下面是我改完之后的代码,亲测返回准确,希望采纳\r\n\r\n``` JavaScript\r\nfunction getOS() {\r\n  var userAgent = 'navigator' in window && 'userAgent' in navigator && navigator.userAgent.toLowerCase() || '';\r\n  var vendor = 'navigator' in window && 'vendor' in navigator && navigator.vendor.toLowerCase() || '';\r\n  var appVersion = 'navigator' in window && 'appVersion' in navigator && navigator.appVersion.toLowerCase() || '';\r\n\r\n  if (/iphone/i.test(userAgent) || /ipad/i.test(userAgent) || /ipod/i.test(userAgent)) return 'ios';\r\n  if (/win/i.test(appVersion) && /phone/i.test(userAgent)) return 'WindowsPhone'; \r\n  //WindowsPhone一定要放在Android前面,否则使用WindowsPhone设备时,还是会返回Android\r\n  if (/android/i.test(userAgent)) return 'Android';\r\n  if (/mac/i.test(appVersion)) return 'MaxOSX';\r\n  if (/win/i.test(appVersion)) return 'Windows';\r\n  if (/linux/i.test(appVersion)) return 'Linux';\r\n}\r\n```"}}
{"actor":{"display_login":"Alienover"}}