Javascript 如何在内容脚本chrome扩展中使用jquery
如何在content.js中使用Jquery 这是我的密码 manifest.jsonJavascript 如何在内容脚本chrome扩展中使用jquery,javascript,jquery,google-chrome-extension,Javascript,Jquery,Google Chrome Extension,如何在content.js中使用Jquery 这是我的密码 manifest.json "background": { "scripts": ["jquery-1.12.2.min.js","background.js"] }, "content_scripts": [{ "matches": [ "http://*/*", "https://*/*"], "js": ["jquery-1.12.2.min.js","content.js"] }],
"background": {
"scripts": ["jquery-1.12.2.min.js","background.js"]
},
"content_scripts": [{
"matches": [ "http://*/*", "https://*/*"],
"js": ["jquery-1.12.2.min.js","content.js"]
}],
"permissions": [
"tabs",
"activeTab",
"http://*/*",
"https://*/*",
"<all_urls>"
]
content.js
chrome.tabs.create({url: "https://www.google.com/search?gws_rd=cr&as_qdr=all&q=" + encodeURIComponent(searchQ)}, function (tab){openSearchLink(tab)});
var createdTabId = 0;
function openSearchLink(tab){
console.log("new tab "+tab.id);
createdTabId = tab.id;
}
// Listen for messages
chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) {
// If the received message has the expected format...
if (msg.text === 'report_back') {
// Call the specified callback, passing
// the web-page's DOM content as argument
var resAry = {};
console.log('dddd-'+$('#bname').val());
resAry['bName'] = $('#bname').val().trim();
sendResponse(resAry);
}
});
resAry['bname']正在返回空响应。其中,当我使用document.getElementById时,我得到了值。在popup.html中添加下面的行就成功了
<script src="jquery-1.12.2.min.js"></script>
首先,您可以检查前端页面上是否有jQuery文件??我检查你的例子,它显示为空?我没有任何头版/popup.html。我正在尝试从加载的选项卡读取dom内容,行在哪里?