【发布时间】:2017-03-17 05:38:15
【问题描述】:
看起来应该没有问题,因为我将 4chan 添加到清单的权限药水,但链接仍然没有打开 4chan.org 的新标签。如果有人能说出我的代码有什么问题,我将不胜感激。
这是我当前的代码:
manifest.json:
{
"manifest_version": 2,
"name": "C-List",
"description": "Never Miss a New Thread Again",
"version": "3.0",
"browser_action": {
"default_icon": "icon.jpg",
"default_popup": "popup.html"
},
"permissions": [
"tabs",
"activeTab",
"https://www.4chan.org/",
"http://www.google.com/"
]
}
popup.html:
<!doctype html>
<html>
<head>
<title>C-List</title>
<script src="popup.js"></script>
</head>
<body>
<div style="background-color:rgb(0,255,80)"></div>
<h3>A New Thread Has Been Posted</h3>
<!-- <a id = "link">4Chan</a>
<a href="https://4chan.org/" class="button">Go to Google</a>
<button id="checkPage">Check it out now!</button>
-->
<button type="button"><a href="https://4chan.org/" class="button">New Thread</a></button>
</body>
</html>
popup.js:
document.addEventListener('DOMContentLoaded', function() {
var checkPageButton = document.getElementById('checkPage');
checkPageButton.addEventListener('click', function() {
chrome.tabs.getSelected(null, function(tab) {
d = document;
var f = d.createElement('form');
f.action = 'https://4chan.org/';
f.method = 'post';
var i = d.createElement('input');
i.type = 'hidden';
i.name = 'url';
i.value = tab.url;
f.appendChild(i);
d.body.appendChild(f);
//f.submit();
});
}, false);
}, false);
chrome.browserAction.onClicked.addListener(function() {
chrome.tabs.create({'url': "https://4chan.org/"});
});
/*
document.addEventListener('DOMContentLoaded', function() {
var link = document.getElementById('checkPage');
// onClick's logic below:
link.addEventListener('click', function() {
hellYeah('xxx');
});
});
【问题讨论】:
标签: javascript html json google-chrome-extension