我想制作一个Chrome扩展程序,允许用户发送包含自动填写的特定文本的电子邮件。我使用的是mailto:
链接,但它无法处理长度超过1024个字符的字符串,并且无法创建HTML链接。有没有办法可以在电子邮件页面(可能是本地存储)中填写其他文本甚至HTML链接?
答案 0 :(得分:1)
不幸的是,根据我的知识,没有原生的chrome / javascript API。我做了一些搜索,找到了一个有人正在研究的开源选项,但它非常骷髅。他希望别人能和他一起跳起来并充实它。
听起来像是在尝试这个:
为了创建URL,您可以使用& body =标记和url对消息进行编码,但是长度有限制。听起来你已经知道如何使用chrome打开一个新标签,这样你就可以创建更短的电子邮件,只使用修改后的URL字符串。我做了类似于我的第一次铬合金拉伸的事情。它看起来像这样。
function sendToUrl(){ chrome.tabs.query({active:true, windowId: chrome.windows.WINDOW_ID_CURRENT}, function(tab) {
//while this seems to generate the URL correctly, gmail limits how long the body text can be therefore this is not a viable solution
//Also there is no javascript API therefore there is no hope of sending an email.
//Need to loop through each tab and not just the first one
var currentTab = tab[0];
var tabInformation = RPATH.getTab(currentTab.id);
var mailUrl = "https://mail.google.com/mail/?view=cm&fs=1&tf=1&su=My%20Subject&to=";
// grab the email addresss from popup.html
mailUrl += document.getElementById("to").value + "&body=";
// get formBody from popup.html
var formBody = document.getElementById("body").value;
...
//I did some other stuff that isn't relevant here
...
//Concat final mailto url
mailUrl = mailUrl + formBody;
chrome.extension.sendMessage({mailUrl: mailUrl}, function(response){ console.log(response.farewell);});
});}
适用于较长的电子邮件正文
这只会让你走到一半。我能想到的唯一选择是将标签分开并填写电子邮件正文。您可以使用append在页面加载完成后修改电子邮件正文。这可能看起来像我下面的内容。注意我正在选择iframe元素,然后在那里找到body标签,最后在标签打开后附加一些html。请注意,电子邮件正文只不过是html所以div,tr,br等标签应该都可以用于创建格式良好的电子邮件。在我之前的示例中,我将表单中的文本作为字符串拉出来。您可以改为使用jquery克隆popup.html页面上的html并附加克隆的html。为简单起见,我只将文本放在附加内容中。
$("iframe#:1t4").find("body.editable").append('<p>My long email body</p>');
我想从那里你可以运行点击事件,但你也可以把它留给用户。