Window navigator.userAgent
ตัวอย่าง
รับ navigator.userAgent:
let agent = navigator.userAgent;
ตัวอย่าง "ลองใช้เอง" เพิ่มเติมด้านล่าง
ความหมายและการใช้งาน
คุณสมบัติuserAgent
ส่งคืนส่วนหัว user-agent ที่เบราว์เซอร์ส่งไปยังเซิร์ฟเวอร์
คุณสมบัติuserAgent
เป็นแบบอ่านอย่างเดียว
ค่าที่ส่งคืน มีข้อมูลเกี่ยวกับชื่อเบราว์เซอร์ เวอร์ชัน และแพลตฟอร์ม
ข้อมูลจำเพาะของเว็บแนะนำว่าเบราว์เซอร์ควรให้ข้อมูลส่วนหัวน้อยที่สุด อย่าคิดว่าคุณสมบัตินี้จะไม่เปลี่ยนแปลงในเบราว์เซอร์ในอนาคต
ไวยากรณ์
navigator.userAgent
คืนมูลค่า
พิมพ์ | คำอธิบาย |
สตริง | ส่วนหัวตัวแทนผู้ใช้เบราว์เซอร์ |
ตัวอย่างเพิ่มเติม
แสดงคุณสมบัติของเนวิเกเตอร์ทั้งหมด:
let text = "<p>Browser CodeName: " + navigator.appCodeName + "</p>" +
"<p>Browser Name: " + navigator.appName + "</p>" +
"<p>Browser Version: " + navigator.appVersion + "</p>" +
"<p>Cookies Enabled: " + navigator.cookieEnabled + "</p>" +
"<p>Browser Language: " + navigator.language + "</p>" +
"<p>Browser Online: " + navigator.onLine + "</p>" +
"<p>Platform: " + navigator.platform + "</p>" +
"<p>User-agent header: " + navigator.userAgent + "</p>";
รองรับเบราว์เซอร์
navigator.userAgent
รองรับในทุกเบราว์เซอร์:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |