Search code examples
javascriptjqueryhtmlmailto

Announce webpage as mailto links handler


I notice that many web-based email providers, when accessing the mailbox, would have the browser (seen in Firefox and Chrome) show the option to add the website as the mailto links handler, so that future mailto: links clicked would open the certain page with email address and subject line passed to the script. How is it done? Is there a cross-browser way to achieve this?


Solution

  • navigator.registerProtocolHandler("mailto",
                                      "https://www.example.com/?uri=%s",
                                      "Example Mail");
    

    Here is a nice document explaining this: https://developer.mozilla.org/en-US/docs/Web-based_protocol_handlers

    This is currently only supported in Opera, Chrome and Firefox but I believe that is as cross-platform a solution as you will find.