Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> JavaScript

วิธีดึงชื่อโค้ดและชื่อผลิตภัณฑ์ของเบราว์เซอร์ใน JavaScript

navigator object ให้ข้อมูลเบราว์เซอร์ มี navigator.product และ navigator.appCodeName

Product Name

ส่วนใหญ่คือ "Gecko"

<html> <body> 
<p id="proname"></p> 
<script> 
    document.getElementById("proname").innerHTML = "the product name is " + navigator.product; 
</script> </body> </html>

ผลลัพธ์

the product name is Gecko

Code Name

ส่วนใหญ่คือ "Mozilla" (Chrome, Firefox, IE, Safari, Opera)

<html> <body> 
<p id="coname"></p> 
<script> 
    document.getElementById("coname").innerHTML = "the code name is " + navigator.appCodeName; 
</script> </body> </html>

ผลลัพธ์

the code name is Mozilla