สรุป:
งานที่สำคัญที่สุดของเราสำหรับการพัฒนาส่วนหน้าคือความเข้ากันได้ความเข้ากันได้ของระบบความเข้ากันได้ของเบราว์เซอร์ ฯลฯ วันนี้ฉันจะแบ่งปันวิธีการตัดสินระบบปฏิบัติการและเบราว์เซอร์ที่ฉันห่อหุ้มไว้ในโครงการ
ระบบปฏิบัติการ:
var os = (function () {var useragent = navigator.useragent.toLowerCase (); return {isipad: /ipad/.test(useragent), isiphone: /iphone os /.test (useragent), isandroid: /android/.test(useragent) /windows mobile /.test (useragent), iswin2k: /windows nt 5.0 /.test (useragent), isxp: /windows nt 5.1 /.test (useragent), isvista: /windows nt 6.0 /. iswin81: /windows nt 6.3 /.test (useragent)};} ());หากคุณต้องการตรวจสอบว่าระบบเป็น iPad คุณจะต้องพิจารณาว่า (os.isipad) {} หรือไม่
เบราว์เซอร์:
var bw = (function () {var useragent = navigator.useragent.toLowercase (); return {isuc: /ucweb/.test(useragent), // uC เบราว์เซอร์ ischrome: /chrome/.test(useragent.subst /firefox/.test(useragent), // firefox isopera: /opera/.test(useragent), // โอเปร่าเบราว์เซอร์ issafire: /safari/.test(useragent) &&! /safari/.test(useragent) &&! /chrome/.test (useragent), // เบราว์เซอร์ Safire IS360: /360se/.test(useragent), // 360 เบราว์เซอร์ Isbaidu: /bidubrowser/.test(useragent) /metasr/.test(useragent), // sogou เบราว์เซอร์ isie6: /msie 6.0 /.test (useragent), // ie6 isie7: /msie 7.0 /.test (useragent), // ie7 isie8: /msie 8.0 /.test IE9 isie10: /msie 10.0 /.test (useragent), // ie10 isie11: /msie 11.0 /.test (useragent), // ie11 islb: /lbbrowser/.test(useragent) /QQBrowser/.test(useragent) // qq เบราว์เซอร์};} ());-
สรุป:
เบราว์เซอร์ได้รับการทดสอบด้วยตัวเอง สิ่งที่อาจมีปัญหาคือเบราว์เซอร์ Chrome เนื่องจากเบราว์เซอร์ส่วนใหญ่ใช้เคอร์เนล webkit ฉันจึงสกัดกั้นการนำทางโครเมี่ยมเพื่อแยกแยะพวกเขา หากตำแหน่งข้อมูลของ Chrome Navigator หรือความยาวหลังจากการเปลี่ยนแปลงของโครเมี่ยมในอนาคตปัญหาจะเกิดขึ้นได้ง่าย แต่ก็โอเคในปัจจุบัน
ทุกวันนี้เนื่องจากเบราว์เซอร์ UC บนโทรศัพท์มือถือมักจะบล็อกโฆษณาของ Baidu แต่อย่าบล็อกโฆษณาของ Google เราสามารถเพิ่มเพื่อพิจารณาว่าเป็นเบราว์เซอร์ UC หรือไม่ มันจะไม่แสดงโฆษณา baidu แต่โฆษณาของ Google จะปรากฏขึ้น
if (navigator.useragent.indexof ('ucbrowser')> -1) {Alert ("UC Browser");} else {// ไม่ใช่การดำเนินการโดย Theuc Browser}ในความเป็นจริงการดำเนินงานพิเศษบางอย่างของเบราว์เซอร์เฉพาะสามารถผ่านได้
JS ได้รับข้อมูลเบราว์เซอร์
ชื่อรหัสเบราว์เซอร์: Navigator.AppCodeName
ชื่อเบราว์เซอร์: Navigator.Appname
หมายเลขเวอร์ชันเบราว์เซอร์: Navigator.Appversion
สนับสนุน Java: Navigator.javaenabled ()
ประเภท MIME (อาร์เรย์): Navigator.mimetypes
แพลตฟอร์มระบบ: navigator.platform
ปลั๊กอิน (อาร์เรย์): navigator.plugins
ตัวแทนผู้ใช้: navigator.useragent