我添加了一个背景页面,其中包含带按钮的表单。我正在使用jQuery来处理DOM和事件。点击搜索按钮后,它无法按预期工作,它应显示警告(“调用的.click()处理程序。”);
更新:在控制台上我得到:
拒绝执行内联脚本,因为它违反了以下内容 内容安全策略指令:“script-src'self' 铬扩展资源:”
下面给出的相关代码:
的manifest.json
{
"manifest_version": 2,
"name" : "my Ext,
"description" : "Copy Rows",
"version" : "1.0",
"content_scripts" : [{
"matches" : ["http://example.com/"],
"js" : ["jquery.js","script.js"]
}],
"background":{
"scripts": ["jquery.js","background.js"]
},
"browser_action": {
"default_title": "Title"
}
}
的script.js
var currentURL = document.location.href;
$(document).ready(function(){
$("#button").click(function()
{
alert( "Handler for .click() called." );
});
});
chrome.extension.onMessage.addListener(function(msg, sender, sendResponse)
{
alert(msg.param);
if (msg.method == "getHTML")
sendResponse({data: "Welcome Bg"});
});
background.js
chrome.browserAction.onClicked.addListener(function(activeTab){
var loaderURL = chrome.extension.getURL("dashboard.html");
chrome.tabs.create({ url: loaderURL });
});
function search()
{
// alert("hi search");
// chrome.tabs.sendMessage(activeTab.id, {method: "getHTML",param:"myParam"}, function(response) {
// alert(response.data);
// });
}
$(document).ready(function()
{
$("#button").click(function()
{
alert( "Handler for .click() called." );
});
});
dashboard.html (我的背景页面)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="jquery.js"></script>
</head>
<body>
<form>
<textarea id="serch"></textarea>
<input id="button" type="button" value="Search" />
</form>
</body>
</html>