当用户单击弹出窗口中的选择按钮时,我正在构建的 chrome 扩展从打开的选项卡中获取选定的文本。我正在尝试为此使用 jquery。
清单.json
{
"manifest_version": 2,
"name": "cap",
"description": "BLAH",
"version": "1.0",
"permissions": [ "tabs",
"https://*/*","http://*/*"
],
"content_scripts": [
{
"matches": ["http://*/*","https://*/*"],
"js": ["selection.js"],
"run_at": "document_start",
"all_frames": true
}
],
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup_main.html"
}
}
我在 popup.html 中包含了 jquery 脚本
<html><head>
<meta charset="utf-8">
<title>popup</title>
<link rel="stylesheet" href="/popup.css">
<script type="text/javascript" src="popup.js"></script>
<script type="text/javascript" src="jquery-1.9.1.min.js"></script>
<!-- <script type="text/javascript" src="js/tag-it.js"></script> -->
</head>
<body>
</body></html>
popup.js
$(document).ready(function(){
$("p").click(function(){
chrome.tabs.getSelected(null, function(tab) {
chrome.tabs.sendRequest(tab.id, {method: "getSelection"}, function (response) {
var text = document.getElementById('text');
text.innerHTML = response.data;
});
});
});
});
在执行此脚本时,我收到错误:
未捕获的 ReferenceError:$ 未定义
请帮忙!