เพิ่มการตรวจสอบ DOMTokenList ใน Chrome 50 แล้ว

แซม โทโรกู๊ด
แซม โทโรกู๊ด

ใน Chrome 50 คุณจะตรวจสอบการรองรับตัวเลือกสำหรับแอตทริบิวต์ HTML บางรายการที่ได้รับการสนับสนุนโดยอินสแตนซ์ DOMTokenList ใน JavaScript ได้ ขณะนี้ สถานที่เหล่านี้ได้แก่:

  • ตัวเลือกแซนด์บ็อกซ์ของ iframe
  • ความสัมพันธ์ของลิงก์ (แอตทริบิวต์ rel หรือ relLink ใน JavaScript)

เรามาแสดงตัวอย่างสั้นๆ กัน

var iframe = document.getElementById(...);
if (iframe.sandbox.supports('an-upcoming-feature')) {
    // support code for mystery future feature
} else {
    // fallback code
}
if (iframe.sandbox.supports('allow-scripts')) {
    // instruct frame to run JavaScript
    // NOTE: this is well-supported, and just an example!
}

เมื่อมีรายการตัวเลือกที่รองรับเพิ่มมากขึ้นและมีการเปลี่ยนแปลง คุณสามารถใช้การตรวจหาฟีเจอร์เพื่อดำเนินการที่ถูกต้องกับเว็บแอปพลิเคชันได้