บทความนี้จะแนะนำวิธีการใช้ JavaScript เพื่อตรวจจับประเภทและหมายเลขเวอร์ชันของเบราว์เซอร์รวมถึงเบราว์เซอร์เสือชีต้าเบราว์เซอร์ Sogou เบราว์เซอร์ Aoyou เบราว์เซอร์ 360 เบราว์เซอร์ 360 เบราว์เซอร์ Safe เบราว์เซอร์ QQ เบราว์เซอร์ Baidu
แผนผังการสืบพันธุ์
รหัสตัวอย่าง
<! doctype html> <html> <head> <meta http-equiv = "content-type" content = "text/html; charset = utf-8"> <title> JavaScript กำหนดประเภทของเบราว์เซอร์ เบราว์เซอร์ Sogou, เบราว์เซอร์ Aoyou, เบราว์เซอร์ความเร็ว 360, 360 เบราว์เซอร์ที่ปลอดภัย, * qq เบราว์เซอร์, เบราว์เซอร์ Baidu, ฯลฯ * สนับสนุนเบราว์เซอร์ต่างประเทศ: เช่น, Firefox, Chrome, Safari, Opera ฯลฯ * ใช้: * Get Browser @author: Xuzengqiang*@Since: 2015-1-27 10:26:11 **/var เบราว์เซอร์ = เบราว์เซอร์ || (ฟังก์ชั่น (หน้าต่าง) {var document = window.document, navigator = window.navigator, agent = navigator.useragent.toLowercase (), // ie8+ สนับสนุนการกลับโหมดที่ใช้โดยเบราว์เซอร์เพื่อแสดงเอกสารปัจจุบัน // ie6, IE7: undefined.ie8: 8 // ie10: 10 (โหมดที่เข้ากันได้ 7 || 8 || 9) iemode = document.documentmode, // chorme chrome = window.chrome || false, system = {// agent agent agent: agent, // isie: /msie/.test(agent) "Like Gecko") <0, // webkit kernel iswebkit: agent.indexof ("webkit")> 0, // เป็นโหมดมาตรฐาน isstrict: document.compatmode === "css1compat" supportscope: function () {return "scoped" ใน document.createelement ("style"); Operaversion: function () {ลอง {if (window.opera) {return agent.match (/opera. (/d.]+)/) [1]; }, // คำอธิบาย: การกรองเวอร์ชัน ถ้าสิ้นสุด! (agent.lensof ("opr")> 0)? )? system.ieversion (): (system.type === "firefox")? agent.match (/firefox // ([/d.]+)/) [1]: (system.type === "chrome")? agent.match (/chrome // (/d.]+)/) (system.type === "safari")? agent.match (/เวอร์ชัน // ([/d.]+)/) [1]: "0"; || ระบบการกลับมา "เบราว์เซอร์ Aoyou"; )> 0) {return 'Sogou Browser';} // Chrome: คุณสามารถใช้ window.chrome && window.chrome.webstore เพื่อตัดสินว่า (Chrome && system.type! ClientInfo.Languages; agent.match (/bidubrowser // (/d.]+)/) [1] || agent.match (/chrome // ([/d.]+)/) [1]; //Object.key () ส่งคืนอาร์เรย์ที่มีคุณสมบัติและเมธอด varkeylen = object.keys (chrome.webstore). locals; มันเป็นเบราว์เซอร์เชลล์มันส่งคืนชื่อเชลล์) System.name = System.shell (); +browser.client.version); </script> </head> <body> </body> </html>สรุป
ข้างต้นเป็นเรื่องเกี่ยวกับบทความนี้ฉันหวังว่ามันจะเป็นประโยชน์ต่อการพัฒนาของทุกคน หากคุณมีคำถามใด ๆ โปรดฝากข้อความเพื่อพูดคุย