Dev : Extensions : Example Code : Creating a XUL mailto: link

From MozillaZine Knowledge Base

(Difference between revisions)

Revision as of 21:24, 25 February 2005

How to create a clickable link which launches the users's default application to compose a mail message

Add this XUL to your extension:

 <text value="Send me email" style="color: blue; cursor: pointer" onclick="sendMeMail();"/>

And add this javascript:

 function sendMeMail() {
   // Taken from browser.js's MailIntegration class
   var mailtoUrl = "";
   var ioService = Components.classes[";1"].getService(Components.interfaces.nsIIOService);
   var uri = ioService.newURI(mailtoUrl, null, null);
   // now pass this url to the operating system
   // a generic method which can be used to pass arbitrary urls to the operating system.
   // aURL --> a nsIURI which represents the url to launch
   var extProtocolSvc = Components.classes[";1"].getService(Components.interfaces.nsIExternalProtocolService);
 if (extProtocolSvc)