在这里,我有最简单的chrome扩展。我注意到JQuery似乎没有在我的内容脚本中执行。然而,普通的javascript运行得很好。我想知道是什么阻止了JQuery的执行。
清单
{
"manifest_version": 2,
"name": "test",
"version": "1.0",
"description": "test",
"background": {
"scripts": ["popup.js"]
},
"content_scripts": [{
"matches": ["http://*/*", "https://*/*"],
"js": ["jquery.js", "content.js"]
}]
}
popup.js
chrome.runtime.onMessage.addListener(function (response, sender,
sendResponse)
{
alert("test");
alert(response.test.toString());
});
内容脚本
chrome.runtime.sendMessage({test:
$(".chapters").first().innerHTML.toString()}, function(response){});
//document.getElementsByClassName("chapters")[0].innerHTML.toString()} works
just fine
发布于 2018-07-30 05:33:03
jQuery没有innerHTML属性。使用.html()就是答案。
https://stackoverflow.com/questions/50093885
复制相似问题