I want to inject jQuery into a web page (with a content script) in a Chrome extension.
I try, but something confuses me.
here is my manifest.json
:
{
"name": "test",
"description": "test content script.",
"version": "0.0.1",
"background": {
"scripts": ["jquery-1.10.2.js", "popup.js"]
},
"permissions": ["tabs", "notifications", "http://*/*", "https://*/*"],
"browser_action": {
"default_title": "test",
"default_icon": "icon.png"
},
"options_page": "manage.html",
"content_scripts": [
{
"matches": ["http://*/*", "https://*/*"],
"js": ["jquery-1.10.2.js"]
}
],
"manifest_version": 2
}
jquery-1.10.2.js:
/*jquery's orign code*/
console.log("end of jquery");
I can see the console message but I still can't use jQuery.
I wrote a simple website and tried to include jQuery through the content script instead of adding it with a <script>
tag.
In the Dev Tool console, I enter window.jQuery
or $("li").siblings()
.
If include jQuery in the page, it works, but if it's injected with a content script, it shows jQuery
as undefined.
Why does this happen?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…