HTML onsecuritypolicyviolation Event Attribute
Description
The onsecuritypolicyviolation event attribute runs a script when the page breaks its Content Security Policy (CSP), for example by loading a script, image or style from a source that the policy does not allow. The event fires on the element that caused the violation and bubbles up to the document and window.
The event is a SecurityPolicyViolationEvent with properties such as blockedURI, violatedDirective, effectiveDirective, originalPolicy, sourceFile and lineNumber. It is useful for testing a new policy with Content-Security-Policy-Report-Only and for logging violations, in addition to the server-side report-to directive.
Syntax
<element onsecuritypolicyviolation="script">
Values
- scriptThe name of the script to use when the event has been triggered.
Example
Browser Support
The following information will show you the current browser support for the HTML onsecuritypolicyviolation event attribute. Hover over a browser icon to see the version that first introduced support for this HTML event attribute.
Desktop





Tablets & Mobile





