FeaturePolicy: allowsFeature() 方法
FeaturePolicy 介面的 allowsFeature() 方法允許對許可權策略 (Permissions Policy) 的各個指令進行內省。如果指定的上下文(或者未指定上下文時的預設上下文)允許使用指定的功能,則返回 true,否則返回 false。
語法
js
allowsFeature(feature)
allowsFeature(feature, origin)
引數
返回值
一個布林值 (Boolean),當且僅當允許使用該功能時為 true。
示例
以下示例查詢文件是否可以透過許可權策略使用攝像頭 API。請注意,如果使用者尚未授予相應的許可權,攝像頭 API 可能會受到許可權 API 的限制。
js
// First, get the Feature Policy object
const featurePolicy = document.featurePolicy;
// Then query feature for specific
const allowed = featurePolicy.allowsFeature("camera");
if (allowed) {
console.log("FP allows camera.");
} else {
console.log("FP does not allows camera.");
}
規範
此特性似乎未在任何規範中定義。瀏覽器相容性
載入中…