在 Chrome 50 版中,您可以查看 JavaScript 中 DOMTokenList
例項支援的部分 HTML 屬性支援選項。
目前,這些地方包括:
- iframe 沙箱選項
- 連結關係 (rel 屬性或 JavaScript 中的 relLink)
讓我們來看看簡單的範例:
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!
}
隨著支援的選項清單不斷增加與變動,您可以使用功能偵測功能為網頁應用程式執行正確的動作。