Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> HTML

Thuộc tính navigator.product trong HTML

Thuộc tính navigator.product trả về tên engine (công cụ render) của trình duyệt.

Cú pháp

navigator.product

Ví dụ

<!DOCTYPE html>
<html>
<style>
  body {
    color: #000;
    height: 100vh;
    background: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%) no-repeat;
    text-align: center;
  }
  .btn {
    background: #db133a;
    border: none;
    height: 2rem;
    border-radius: 20px;
    width: 330px;
    display: block;
    color: #fff;
    outline: none;
    cursor: pointer;
    margin: 1rem auto;
  }
  .show { font-size: 1.2rem; color: #fff; }
</style>
<body>
<h1>Demo navigator.product</h1>
<button class="btn" onclick="display()">Hiển thị Engine trình duyệt</button>
<div class="show"></div>
<script>
  function display() {
    document.querySelector(".show").innerHTML = "Tên engine: " + navigator.product;
  }
</script>
</body>
</html>

Kết quả

Nhấn "Hiển thị Engine trình duyệt". Kết quả thường là "Gecko" (Firefox, Chrome, Edge, Safari đều trả về Gecko vì lý do tương thích).

Lưu ý: Giá trị này không còn phản ánh engine thực tế (Blink, WebKit, Gecko) do lịch sử tương thích web.