这是
实验性技术
检查
浏览器兼容性表格
要小心谨慎在生产中使用这之前。
allowsFeature()
方法在
FeaturePolicy
interface enables introspection of individual directives of the Feature Policy it is run on. It returns a
布尔
也就是
true
if and only if the specified feature is allowed in the specified context (or the default context if no context is specified).
const allowed = FeaturePolicy.allowsFeature(<feature>)
or
const allowed = FeaturePolicy.allowsFeature(<feature>, <origin>)
Feature name
A specific feature name must be specified.
Origin name
可选
An origin URL to check the feature on. If it is omitted the default origin is used.
A
布尔
也就是
true
if and only if the feature is allowed.
The following example queries whether or not the document is allowed to use camera API by the Feature Policy. Please note that Camera API might be restricted by the Permissions API, if the user did not grant the corresponding permission yet.
// 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.")
}
| 规范 | 状态 | 注释 |
|---|---|---|
|
Feature Policy
The definition of 'allowsFeature' in that specification. |
编者草案 | 初始定义。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
allowsFeature
|
Chrome
74
|
Edge 79 | Firefox 65 | IE No |
Opera
62
|
Safari No | WebView Android 74 |
Chrome Android
74
|
Firefox Android 65 |
Opera Android
48
Disabled
|
Safari iOS No | Samsung Internet Android 11.0 |
完整支持
不支持
实验。期望将来行为有所改变。
用户必须明确启用此特征。