I have a URL shortening Chrome extension called Shrtr. Right now, it allows users to copy the shortened URL to clipboard, but in the next version, I've added the ability to email the shortened URL, using a mailto:
link (i.e. mailto:?subject=<original page title>&body=<short URL>
).
The problem is, you cannot just assign document.location.href = 'mailto...';
from an extension. The following 2 methods worked for me, but with both, I end up with an open blank tab in the browser:
Method 1: window.open
var wnd = window.open(emailUrl);
setTimeOut(function() {
wnd.close();
}, 500);
Notice the need to wait before closing the window. This works (i.e. mail client new message dialog appears, pre-populated), but the new tab remains open.
Method 2: using chrome.tabs
chrome.tabs.create({ url: emailUrl }, function(tab) {
setTimeOut(function() {
chrome.tabs.remove(tab.id);
}, 500);
});
Again, works - but tab remains open. Any ideas?