Chrome扩展页面需要动态绑定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.οnclick=function(){
		document.getElementById("player_sidebar").style.width = 100;
	}

参考:

http://www.cnblogs.com/dudu/archive/2012/11/22/chrome_extension.html

动态绑定方法:http://bbs.csdn.net/topics/390563932

你可能感兴趣的:(javascript)