Chrome扩展页面动态绑定JS事件提示错误_javascript技巧
来源:懂视网
责编:小采
时间:2020-11-27 21:19:26
Chrome扩展页面动态绑定JS事件提示错误_javascript技巧
Chrome扩展页面动态绑定JS事件提示错误_javascript技巧:问题描述: 当开发Chrome扩展时,页面的popup.html中需要js的时候,直接将JS写在动态绑定JS事件会提示: Refused to execute inline script because it violates the following Content Security Policy directive
导读Chrome扩展页面动态绑定JS事件提示错误_javascript技巧:问题描述: 当开发Chrome扩展时,页面的popup.html中需要js的时候,直接将JS写在动态绑定JS事件会提示: Refused to execute inline script because it violates the following Content Security Policy directive

问题描述:
当开发Chrome扩展时,页面的popup.html中需要js的时候,直接将JS写在动态绑定JS事件会提示:
Refused to execute inline script because it violates the following Content Security Policy directive: “script-src ‘self' chrome-extension-resource:”..
解决办法:
在popup.html中引用外部的js文件动态绑定JS事件,例如:
代码如下:
Chrome扩展页面动态绑定JS事件提示错误_javascript技巧
Chrome扩展页面动态绑定JS事件提示错误_javascript技巧:问题描述: 当开发Chrome扩展时,页面的popup.html中需要js的时候,直接将JS写在动态绑定JS事件会提示: Refused to execute inline script because it violates the following Content Security Policy directive