这是
实验性技术
检查
浏览器兼容性表格
要小心谨慎在生产中使用这之前。
sample
只读特性在
SecurityPolicyViolationEvent
接口是
DOMString
representing a sample of the resource that caused the violation.
let sample = violationEventInstance.sample;
A
DOMString
containing a sample of the resource that caused the violation, usually the first 40 characters. This will only be populated if the resource is an inline script, event handler, or style — external resources causing a violation will not generate a sample.
document.addEventListener("securitypolicyviolation", (e) => {
console.log(e.sample);
});
| 规范 | 状态 | 注释 |
|---|---|---|
|
Content Security Policy Level 3
The definition of 'sample' in that specification. |
工作草案 | 初始定义 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
sample
|
Chrome 59 | Edge ≤18 |
Firefox
63
|
IE 不支持 No | Opera 46 | Safari Yes | WebView Android 59 | Chrome Android 59 |
Firefox Android
63
|
Opera Android 43 | Safari iOS Yes | Samsung Internet Android 7.0 |
完整支持
不支持
用户必须明确启用此特征。