判斷操做系統和瀏覽器的js代碼linux
navigator.userAgent:userAgent 屬性是一個只讀的字符串,聲明瞭瀏覽器用於 HTTP 請求的用戶代理頭的值。
navigator.platform:platform 屬性是一個只讀的字符串,聲明瞭運行瀏覽器的操做系統和(或)硬件平臺。
android
判斷操做系統類型
win操做系統chrome
1 navigator.platform == "Win32" 2 navigator.platform == "Windows"
win2000操做系統瀏覽器
1 /Windows NT 5.0/i.test(navigator.userAgent)
WinXP操做系統微信
1 /Windows NT 5.1/i.test(navigator.userAgent)
Win2003操做系統
spa
1 /Windows NT 5.2/i.test(navigator.userAgent)
WinVista操做系統操作系統
1 /Windows NT 6.0/i.test(navigator.userAgent)
Win7操做系統firefox
1 /Windows NT 6.1/i.test(navigator.userAgent)
mac操做系統代理
1 navigator.platform == "Mac68K" 2 navigator.platform == "MacPPC" 3 navigator.platform == "Macintosh" 4 navigator.platform == "MacIntel"
unix操做系統unix
1 navigator.platform == "X11"
linux操做系統
1 /Linux/i.test(navigator.userAgent)
andorid操做系統
1 if(/Linux/i.test(navigator.userAgent)){ 2 if(/android/i.test(navigator.userAgent.toLowerCase())){ 3 return "android"; 4 } 5 }
判斷瀏覽器類型
ie瀏覽器:
1 /ie/i.test(navigator.userAgent.toLowerCase());
firefox瀏覽器
1 /firefox/i.test(navigator.userAgent.toLowerCase());
谷歌瀏覽器
1 /chrome/i.test(navigator.userAgent.toLowerCase());
opera瀏覽器
1 /opera/i.test(navigator.userAgent.toLowerCase());
safari瀏覽器
1 /safari/i.test(navigator.userAgent.toLowerCase());
微信瀏覽器
1 /micromessenger/i.test(navigator.userAgent.toLowerCase());