Reputation: 11545
I was wondering what elements can contain javascript code in their attributes? I know that it's allowed in link "href" (javascript://) and all on* attributes.
Do browsers execute javascript code from any other attributes?
Upvotes: 0
Views: 139
Reputation: 57719
It's allowed in href
because that's what gets put into your browser address bar. Similarly you can use something like:
document.location.href = 'javascript:alert("hello");';
There isn't really a good reason to put JavaScript in href
though. It's very limited in it's usefulness. I would suggest the proper route of onclick handlers or some setup that reacts to changes in the #
(hash).
Upvotes: 2