使用以下代码,如果用户点击Chrome扩展程序图标,我会尝试在标签中打开mailto:
链接。但是,单击该图标后,不会执行任何操作。
的manifest.json
{
"manifest_version": 2,
"name": "Extension",
"description": "Description",
"version": "1.0",
"browser_action": {
"default_icon": "icon.png"
},
"permissions": [
"tabs"
]
}
popup.js
chrome.browserAction.onClicked.addListener(function tab) {
var emailUrl = "mailto:address@domain.com";
chrome.tabs.create({ url: emailUrl });
};
答案 0 :(得分:2)
您的代码存在多方面问题:
我建议使用eventPage来触发电子邮件链接:
<强>的manifest.json 强>
{
"manifest_version": 2,
"name": "Extension",
"description": "Description",
"version": "1.0",
"browser_action": {
"default_icon": "icon.png"
},
"background": {
"scripts": ["eventPage.js"],
"persistent": false
}
}
<强> eventPage.js 强>
chrome.browserAction.onClicked.addListener(tab => {
chrome.tabs.create({ url: 'mailto:address@domain.com' })
})