设置script-src 'nonce-2726c7f26c' 'self';之后,script的nonce也加了同样的数字,但是点击按钮还是不好用
<form action="about:blank">
first name:<input type="text" name="fname" /><br/>
last name :<input type="text" name="lname" /><br/>
e-mail:<input type="email" name="email" autocomplete="off" /><br/>
<button type="button">submit</button>
</form>
<script nonce="2726c7f26c">
var btn = document.getElementsByTagName('button');
btn[0].onclick = doSubmitForm
function doSubmitForm(){
alert(1)
}
</script>
该文博主提到了,当你使用了 Content-Security-Policy 设置后,对象上不能写事件触发,例如 onclick,你需要在 js 中注册这个事件