Why discourage the use of event handler content attributes? #311
Replies: 2 comments
-
Thanks for opening this one @code86, I've transferred it to a discussion to get some more feedback and opinions on this. |
Beta Was this translation helpful? Give feedback.
-
I believe that "event handler attributes" are treated by CSPs as inline scripts:
(https://w3c.github.io/webappsec-csp/#html-integration) ...so they are blocked by default. https://w3c.github.io/webappsec-csp/#unsafe-hashes-usage has some more information:
I wonder if we should move this back to being an issue? I do think the page could be more precise than "may also be blocked by content security policies". |
Beta Was this translation helpful? Give feedback.
-
MDN URL
https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes
What specific section or headline is this issue about?
Event handler attributes
What information was incorrect, unhelpful, or incomplete?
This webpage warns: "The use of event handler content attributes is discouraged. The mix of HTML and JavaScript often produces unmaintainable code, and the execution of event handler attributes may also be blocked by content security policies."
What did you expect to see?
The above suggests that using addEventListener is preferred to using "event handler attributes".
It would be helpful to provide supporting links / references / examples on how "event handler attributes", but not addEventListener method, would be blocked by content security policies.
Providing a sense of how widespread this problem is would help too.
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/html/attributes
Beta Was this translation helpful? Give feedback.
All reactions