【发布时间】:2014-01-15 11:45:45
【问题描述】:
我想尝试 Chrome 扩展程序有一段时间了,而 Chrome 一直困扰着我的一件事是,单击活动的 mailto: 链接会在同一个选项卡中打开 GMail(如果它是您的处理程序),然后导航离开从页面。
当您使用 Gmail 处理程序单击 mailto: 链接时,它会获取链接的电子邮件地址并将其附加到撰写窗口:
https://mail.google.com/mail/?view=cm&fs=1&tf=1&source=mailto&to=youremail@somesite.com
我想做的是创建一个扩展程序,它为我提供了一个上下文菜单选项来撰写新电子邮件。我已经掌握了基础知识(见下文),但我不知道如何让收件人电子邮件地址自动包含在弹出窗口中。
manifest.json:
"background": {
"scripts": [ "background.js" ]
},
"description": "Creates a context menu option which copies the selected address into a new Gmail compose window.",
"manifest_version": 2,
"name": "New Gmail Window",
"permissions": [ "tabs", "contextMenus" ],
"version": "0.1"
}
background.js
function getEmail(info, tab) {
chrome.windows.create({
url: "https://mail.google.com/mail/?ui=2&view=cm&fs=1&tf=1&shva=1&", // This is the URL I need to figure out.
width: 640,
height: 700,
focused: true,
type: "popup",
})
}
chrome.contextMenus.create({
title: "Send Email",
contexts: ["selection"],
targetUrlPatterns: ["mailto:* "],
onclick: getEmail,
});
【问题讨论】:
标签: javascript google-chrome google-chrome-extension