I've been searching all over the internet to find out how to create a mailto
share button that opens up a new window in which the user can then type in the email address of his choice to send to. I've an attached a sequential set of images as operational example:
What is the trick to this? Why can't I find any info on how to write such code ....absolutely nowhere on Stack Overflow either!
As of right now this is the code that I have:
$('.share-page-on-Email').click(function() {
window.open("mailto:"+emailTo+'?cc='+emailCC+'&subject='+emailSub+'&body='+emailBody, '_self');
});
View my prototype Email share button at my Code Pen here: https://codepen.io/IDCoder/full/rpdBQJ/
Thanks in advance for your help!
You can use
navigator.registerProtocolHandler()
to set specific domains to handle specific protocols as demonstrated by @PaulIrish at Getting Gmail to handle all mailto: links with registerProtocolHandler..registerProtocolHandler()
must be called at the origin where the protocol is to be handled by the web application, else an error occurs.For example, you can navigate to "https ://mail.google.com/mail/#inbox", then at
console
which should launch a
window
having title "Compose Mail", with Subject and Body populated.To include "cc" you can place
within the string following last
on the
line, see mailto with multiple cc addresses.
Or write the service for your own online email application to achieve the same handling of requests for specific protocols.
You can use window.location.href like this:
window.location.href = 'mailto:email@domain.com'
I recommend never using that mailto: feature as it behaves unpredictably, different on different devices and sometimes fails alltogether. You could create a page just to take the email string then do whatever you want with it server side. Make the popup/popover small like: