【发布时间】:2012-08-15 15:22:22
【问题描述】:
我正在尝试进入 Chrome 扩展的神奇世界。 现在我已经建立了我的清单,试图加载 jquery。
{
"name": "Test Extension",
"version": "0.1",
"manifest_version": 2,
"description": "First try",
"options_page": "options.html",
"content_scripts": [{
"matches": ["chrome-extension://*/*"],
"js": ["jquery.js", "popup.js"],
"run_at": "document_end"
}],
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html",
"default_title": "Click me!"
}
}
实际上尝试重新加载扩展程序告诉我“匹配项”与有效架构不匹配。
但这还不是全部。为了克服它,我尝试将“匹配”值更改为*://*/* 并重新加载。
好吧,扩展似乎加载正确,但似乎 jquery 没有加载,因为我可以从 popup.js 得到的错误告诉我
Uncaught ReferenceError: $ is not defined
其实 HTML 只是:
<!doctype html>
<html>
<head>
<title>Test Extension</title>
<link rel="stylesheet" style="text/css" src="style.css">
</head>
<body>
<div id="test"></div>
</body>
</html>
<script type="text/javascript" src="popup.js"></script>
popup.js 代码就是这样做的:
$("#test").html("Foo!");
【问题讨论】:
-
您的意思是
$("#test").html("Foo!");而不是$.('#test')? -
是的。那是一个分散注意力的错误。我要编辑这个问题。真丢人。当然,错误现在是一个更具指示性的“$ 未定义”
标签: jquery google-chrome-extension manifest