Better way to call javascript function in a tag

前端 未结 4 413
时光说笑
时光说笑 2020-12-08 13:28

Which of the following ways is a better way to call a js function from an a tag?

LINK

4条回答
  •  天命终不由人
    2020-12-08 14:07

    Modern browsers support a Content Security Policy or CSP. This is the highest level of web security and strongly recommended if you can apply it because it completely blocks all XSS attacks.

    Both of your suggestions break with CSP enabled because they allow inline Javascript (which could be injected by a hacker) to execute in your page.

    The best practice is to subscribe to the event in Javascript, as in Konrad Rudolph's answer.

提交回复
热议问题