Chrome扩展页面动态绑定JS事件提示错误

开发Chrome扩展时,页面的popup.html中需要js的时候,直接将JS写在动态绑定JS事件会提示错误,下面有个不错的解决方法,大家可以参考下

问题描述:

当开发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事件,例如:
复制代码 代码如下:



test.js中:
复制代码 代码如下:

var listbox = document.getElementById("showlist");
listbox.onclick=function(){
document.getElementById("player_sidebar").style.width = 100;
}

以上就是Chrome扩展页面动态绑定JS事件提示错误的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » JavaScript 教程