You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{Element,Document}: securitypolicyviolation event: wrong claim about "you can't assign a handler to the property until the elements have been loaded"
#35410
Open
Josh-Cena opened this issue
Aug 12, 2024
· 0 comments
· May be fixed by #38685
What specific section or headline is this issue about?
No response
What information was incorrect, unhelpful, or incomplete?
You should add the handler for this event to a top level object (i.e. {{domxref("Window")}} or {{domxref("Document")}}).
While the property exists in HTML elements, you can't assign a handler to the property until the elements have been loaded, by which time this event will already have fired.
What did you expect to see?
This paragraph rephrased, to something similar to:
You should generally add the handler for this event to a top level object (i.e. listen for the {{domxref("Document.securitypolicyviolation_event", "securitypolicyviolation")}} event on {{domxref("Document")}} instead).
While the event may originate from HTML elements, JavaScript that assigns a handler to the element usually executes after the element has been loaded, by which time this event has already fired.
You can only successfully listen to this event if the loading starts after the listener is attached, usually by dynamically modifying the fetch target via JavaScript.
And, later, the example should demonstrate a dynamically constructed element.
constimg=document.createElement("img");img.onsecuritypolicyviolation=console.log;img.src="https://...";// Fetching starts here, which is after the handler is attached
Do you have any supporting links, references, or citations?
MDN URL
https://developer.mozilla.org/en-US/docs/Web/API/Element/securitypolicyviolation_event
What specific section or headline is this issue about?
No response
What information was incorrect, unhelpful, or incomplete?
What did you expect to see?
This paragraph rephrased, to something similar to:
And, later, the example should demonstrate a dynamically constructed element.
Do you have any supporting links, references, or citations?
No response
Do you have anything more you want to share?
No response
MDN metadata
Page report details
en-us/web/api/element/securitypolicyviolation_event
The text was updated successfully, but these errors were encountered: