JavaScript cung cấp đối tượng navigator để lấy chi tiết trình duyệt. Có navigator.product và navigator.appCodeName để lấy tên sản phẩm và tên mã. Thảo luận từng cái.
Tên sản phẩm (Product name)
product property trả về tên sản phẩm, hầu hết trình duyệt là Gecko.
Ví dụ
<html> <body> <p id="proname"></p> <script> document.getElementById("proname").innerHTML = "the product name is " + navigator.product; </script> </body> </html>
Kết quả
the product name is Gecko
Tên mã (Code name)
appCodeName trả về tên mã trình duyệt. Thường là "Mozilla" cho Chrome, Firefox, IE, Safari, Opera.
Ví dụ
<html> <body> <p id="coname"></p> <script> document.getElementById("coname").innerHTML = "the code name name is " + navigator.appCodeName; </script> </body> </html>
Kết quả
the code name name is Mozilla