Skip to content

Commit

Permalink
element example
Browse files Browse the repository at this point in the history
  • Loading branch information
hamishwillee authored Aug 9, 2024
1 parent a34b0df commit 9d74140
Showing 1 changed file with 4 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ A {{domxref("SecurityPolicyViolationEvent")}}. Inherits from {{domxref("Event")}

The code below shows how you might add an event handler function using the `onsecuritypolicyviolation` global event handler property or `addEventListener()` on the top level `Window` (you could use exactly the same approach on `Document`).

> [!NOTE]
> The example doesn't assign the handler directly to an element because, as noted above, for elements defined in HTML, the event would fired before this code could run.
> You might however add the event listener directly to an element that is dynamically constructed!
```js
window.onsecuritypolicyviolation = (e) => {
// Handle SecurityPolicyViolationEvent e here
Expand Down

0 comments on commit 9d74140

Please sign in to comment.