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

Thuộc tính navigator.platform trong HTML

Thuộc tính navigator.platform trả về nền tảng (hệ điều hành/hardware) mà trình duyệt được biên dịch chạy.

Cú pháp

navigator.platform

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.platform</h1>
<button class="btn" onclick="display()">Hiển thị nền tảng</button>
<div class="show"></div>
<script>
  function display() {
    document.querySelector(".show").innerHTML = "Nền tảng: " + navigator.platform;
  }
</script>
</body>
</html>

Kết quả

Nhấn "Hiển thị nền tảng". Kết quả ví dụ: Win32 (Windows 32/64-bit), MacIntel (macOS), Linux x86_64, iPhone, Android.