我想使用图片作为按钮(setting.png),并点击在新标签中打开一个URL。如何在Chrome扩展内的新选项卡中打开URL?
我popup.html:
<html>
<head>
<style>
</style>
</head>
<body>
<a href = "http://google.com" id="link"><img src="setting.png" width="30px" height="auto"></a>
<script src ="javascript.js"></script>
</body>
</html>
manifest.json的:
{
"manifest_version": 2,
"name": "",
"options_page": "options.html",
"background": {
"scripts": [
"background.js"
]
},
"description": "",
"version": "1.5",
"offline_enabled": true,
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"icons": { "16": "icon16.png",
"32": "icon32.png",
"48": "icon48.png",
"64": "icon64.png",
"128": "icon128.png" },
"permissions": [
"activeTab",
"https://ajax.googleapis.com/",
"storage",
"tabs"
]
}
javascipt.js:
window.addEventListener('click',function(e){
if(e.target.href!==undefined){
chrome.tabs.create({url:e.target.href})
}
})
所以,当我点击图片,我想开了新标签中的网址。谢谢!
请下次使用搜索。 – Xan
对不起@xan,但这不符合我的需要。 – Han
它明确做到了。您不使用jQuery,因此接受的答案不适用,但有2个非jQuery答案。 – Xan