我花了幾個小時試圖弄清楚我的Chrome擴展有什麼問題。我知道我的function.js代碼是好的,因爲它可以與我鏈接到的html頁面一起工作,但是對於擴展名可能不適用? 所有幫助表示讚賞爲什麼我的Chrome擴展工作不正常?
manifest.json
{
"manifest_version": 2,
"name": "Font Find",
"description": "This extension allows you to click on any text, and find out what font it is written in.",
"version": "1.0",
"background": {
"page": "popup.html",
"persistent": true
},
"permissions": [
"activeTab",
"http://*/*",
"https://*/*"
],
"browser_action": {
"default_title": "Find the Font",
"default_icon": "icon.png"//,
// "default_popup": "popup.html"
},
"background": { "scripts": ["jquery.min.js"] },
"content_scripts": [
{
"matches": [
"http://*/*",
"https://*/*"
],
"js": [
"function.js"
]
}
]
}
popup.html
文件(注意是不是設置爲彈出式)
<!DOCTYPE HTML>
<html>
<head>
<!-- <link rel="stylesheet" href="popup.css"/> -->
<script src="jquery.min.js"></script>
<script src="popup.js"></script>
<script src="function.js"></script>
</head>
</html>
function.js
文件
"use strict";
$("body").append('Test');
document.body.ondblclick = function(event){
//event.stopPropagation();
var target = event.target || event.srcElement;
alert("What you clicked on:" + $(target).text() + " It's font-family is: " + $(target).attr("font-family"));
}
function.js
文件
chrome.browserAction.onClicked.addListener(function (tab) {
chrome.tabs.executeScript({
file: "function.js"
});
});
投票結束作爲題外話,因爲它是「爲什麼不是這個代碼工作?」題。請更具體一些。例如,你有沒有錯誤?它是如何「不工作」?你是否正確安裝? –
對不起,如果我不遵守堆棧的所有規則,我很難提出問題。我沒有收到錯誤。我確實安裝了它。當我點擊我的圖標時,我應該可以雙擊任何一段文字,並會彈出一個警告框告訴我它的字體系列。 – Steven
歡迎來到SO!我猜測安裝可能有問題。您是否正確地將其添加到Chrome? –