admin管理员组文章数量:1253102
I see it used on websites so I"m unsure. Can I use OnChange and onClick inside my html ? I'm a little confused, I thought javascript was deprecated in html ? However, I think these two actions are part of DOM GlobalEventHandlers ? I think jquery uses it alot so I should be fine ?
<select id="select" class="button" onChange=getValue()>
I think what is meant by not using js in html is
<p javascript:code> </p>
Well, I got an error but I think it has to do with the way chrome extension works. I'll have to look into this:
Refused to execute inline event handler because it violates the following Content Security Policy directive: "script-src 'self' blob: filesystem: chrome-extension-resource:". Either the 'unsafe-inline' keyword, a hash ('sha256-...'), or a nonce ('nonce-...') is required to enable inline execution.
I see it used on websites so I"m unsure. Can I use OnChange and onClick inside my html ? I'm a little confused, I thought javascript was deprecated in html ? However, I think these two actions are part of DOM GlobalEventHandlers ? I think jquery uses it alot so I should be fine ?
<select id="select" class="button" onChange=getValue()>
I think what is meant by not using js in html is
<p javascript:code> </p>
Well, I got an error but I think it has to do with the way chrome extension works. I'll have to look into this:
Refused to execute inline event handler because it violates the following Content Security Policy directive: "script-src 'self' blob: filesystem: chrome-extension-resource:". Either the 'unsafe-inline' keyword, a hash ('sha256-...'), or a nonce ('nonce-...') is required to enable inline execution.
Share Improve this question asked Jan 29, 2016 at 2:11 ritchieritchie 4551 gold badge4 silver badges13 bronze badges 3- Sorry, I'm a little confused as to what your exact question is. Do you think you could clarify? Are you asking about Chrome extensions? – BurningLights Commented Jan 29, 2016 at 2:15
- 1 @BurningLights I was asking if I could use onClick and onChange in my html or is it deprecated ? – ritchie Commented Jan 29, 2016 at 2:21
- 2 According to MDN (developer.mozilla/en-US/docs/Web/Guide/HTML/…) event attributes should be avoided. But, I couldn't find anything about them being deprecated. – BurningLights Commented Jan 29, 2016 at 2:50
2 Answers
Reset to default 10Sounds like you're writing a Google Chrome extension. You cannot use any inline event handlers (i.e, onEvent
attributes) under the security model used for extension pages*. All events must be set up from Javascript code, e.g.
document.getElementById("select").addEventListener("change", getValue);
or, if you're using jQuery:
$("#select").change(getValue);
*: Specifically, the Content Security policy for Chrome extensions.
You can use onclick in html and you have to write a javascript function that onclick will do. Using onclick does not required jQuery and you can just do pure javascript.
HTML
<button onclick="foo()">Do something</button>
<p id="foo"></p>
JS
function foo() {
document.getElementById("foo").innerHTML = "Foo";
}
本文标签: javascriptIs onChange or onClick deprecated in html GlobalEventHandlersStack Overflow
版权声明:本文标题:javascript - Is onChange or onClick deprecated in html GlobalEventHandlers? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1740313173a2259806.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论