我的 Chrome 扩展程序是灰色的,并且不会显示弹出窗口。我试图让它在“https://scratch.mit.edu ”和所有子域上工作,但它在每个站点上都是灰色的。该弹出窗口也不会显示在任何网站上。
manifest.json:
{
"manifest_version": 2,
"background": {
"page": "background.html"
},
"page_action": {
"default_icon": {
"19": "images/icon19.png",
"38": "images/icon38.png"
},
"default_title": "Scratch theme loader",
"default_popup": "popup.html"
},
"permissions": [
"storage",
"declarativeContent",
"https://scratch.mit.edu/*",
"https://pastebin.com/raw/*"
]
}
背景.html:
<!DOCTYPE html>
<html>
<head>
<title>Background operation for Scratch Themes</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<script type="text/javascript">
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
if (tab.url.indexOf('https://scratch.mit.edu') > -1) {
chrome.pageAction.show(tabId);
} else {
chrome.pageAction.hide(tabId);
}
});
</script>
</body>
</html>
popup.html:
<!DOCTYPE html>
<html>
<head>
<title>Scratch Themes</title>
<style>
body {
min-width: 357px;
overflow-x: hidden;
font-family: "Segoe UI", "Lucida Grande", Tahoma, sans-serif;
font-size: 100%;
}
img {
align: center;
}
</style>
</head>
<body>
<ul>
<li>
<img src = "images/S_Themes.png">
</li>
<li>
<p>Choose which theme you would like to use:</p>
<form action="">
<input type="radio" name="example" value="1"> Example 1<br>
<input type="radio" name="example" value="2"> Example 2<br>
<input type="radio" name="example" value="3"> Example 3
</form>
</li>
</body>
</html>
最佳答案
您必须将所有 javascript 代码放在 js 文件中,后台、弹出窗口和其他扩展页面中不允许使用 html 脚本,甚至 onclick 属性也不允许。
关于javascript - Chrome 扩展程序呈灰色并且不会显示弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36246834/