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

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

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

  2020-05-13 我要评论
问题描述:

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

<script type="text/javascript" charset="utf-8" src='test.js'></script>

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

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

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们