【发布时间】:2015-12-09 12:47:16
【问题描述】:
我想将图像用作按钮 (setting.png),然后单击在新选项卡中打开 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})
}
})
所以当我点击图片时,我想在新标签页中打开 URL。谢谢!
【问题讨论】:
-
下次请使用搜索。
-
对不起@xan,但这不符合我的需要。
-
它明确地做到了。您不使用 jQuery,因此接受的答案不适用,但那里有 2 个非 jQuery 答案。
-
当然,它可能无法以复制和粘贴的方式满足您的需求,但是您需要更清楚地指定您的需求,并显示您尝试如何应用该答案并失败。
-
好的,谢谢。我已经更新了我的代码。我尝试使用stackoverflow.com/a/26216955/5586484。但这似乎不起作用。你能告诉我哪里出错了吗?
标签: javascript html google-chrome google-chrome-extension