วันนี้ฉันจะแนะนำวิธีใช้ JS เพื่อตัดสินแพลตฟอร์มไคลเอนต์มือถือและแพลตฟอร์มระบบ:
<script type = "text/javascript"> // มือถือตัดสินฟังก์ชันเบราว์เซอร์และระบบปฏิบัติการระบบแพลตฟอร์ม checkplatform () {ถ้า (//android/i.test (navigator.useragent)) {document.write ("นี่คือ Android'Browser"); // แพลตฟอร์ม} if (/(iphoneipadipodios) /i.test (navigator.useragent)) {document.write ("นี่คือ ios'browser."); // นี่คือเบราว์เซอร์ภายใต้แพลตฟอร์ม iOS} ถ้า (/linux/i.test (navigator.useragent) แพลตฟอร์ม Linux} if (/linux/i.test (navigator.platform)) {document.write ("นี่คือระบบปฏิบัติการ Linux"); // นี่คือแพลตฟอร์มระบบปฏิบัติการ Linux} ถ้า (/micromessenger/i.test (navigator.useragent) {document.write แพลตฟอร์ม}} $ (เอกสาร). ready (function () {alert (navigator.platform); dexplatform ();}); </script>โปรดทราบว่ารหัสด้านบนใช้ jQuery jQuery จะต้องโหลดก่อนที่จะสามารถทำงานได้ แน่นอนคุณสามารถลบฟังก์ชั่นทริกเกอร์
ฉันจะไม่ตัดสินบนแพลตฟอร์มระบบปฏิบัติการพีซีที่นี่ ฉันจะพูดถึงวิธีการตัดสิน ตัวอย่างเช่นคุณสามารถรับแพลตฟอร์มระบบปฏิบัติการโดยใช้ document.write (navigator.platform); Win32 จะแสดงภายใต้ Win32; Win64 จะแสดงภายใต้ Win64 ฯลฯ
ด้านล่างบรรณาธิการของ Wulin.com จะเพิ่มฟังก์ชั่นที่ดีให้คุณ
<script type = "text/javascript"> var browser = {เวอร์ชัน: function () {var u = navigator.useragent, app = navigator.appversion; return {trident: u.indexof ('trident')> -1, presto: u.indexof ('presto') u.indexof ('gecko')> -1 && u.indexof ('khtml') == -1, มือถือ: !! u.match (/applewebkit.*mobile.*/) || !! u.match (/applewebkit/), ios: !! u.match (// (i [^;]+; (u;)? cpu.+mac os x/), Android: u.indexof ('Android')> -1 || u.indexof ('linux') U.Indexof ('iPad')> -1, WebApp: U.Indexof ('Safari') == -1, qqbrw: u.indexof ('mqqbrowser')> -1, weixin: U.Indexof ('micromessenger')> -1, uClowend: U.IndExof ( U.Indexof ('rv: 1.2.3.4')> -1, ucweb: function () {ลอง {return parsefloat (u.match (/ucweb/d+/./d+/gi) .toString () (/d+/./d+/). tostring () {return true;} else {return false;}}} (), symbian: u.indexof ('symbian')> -1, ucsb: u.indexof ('firefox/1.')> -1};} ()} if (browser.versions.qqbrw) เบราว์เซอร์ ");} </script>ทดสอบเป็นการส่วนตัวมีประโยชน์มาก