spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / javascript / column70


The Mailtool

Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

Writing a Script-Based Tool

The second mailto: URL tool we want to present here is based on a script only. It sets the message's details and then pops up a new mail message form, with all the details filled in. When you click the button below, it calls the function popupMessage(). Go ahead and click the button. See how the new mail message appears:

The button above is constructed as:


<FORM>
<INPUT TYPE="button" NAME="Test" Value="Test mailto:
  URL" onClick="popupMessage()">
</FORM>

The function popupMessage() is defined as follows:

function popupMessage() {
  // SET MESSAGE VALUES
  var to = "tomer@netscent.com";
  var cc = "yehuda@internet.com";
  var bcc = "tomer@internet.com";
  var subject = "Comments about your tips";
  var body =
    "Tomer and Yehuda,\n\n\tI'd like to suggest the following
      improvements to your tips: \n" +
    "\nFirst, ..." +
	"\nAlso, sometimes...." +
    "\n\nSincerely,\n\n" + "Your faithful reader...";

  // BUILD MAIL MESSAGE COMPONENTS
  var doc = "mailto:" + to +
    "?cc=" + cc +
    "&bcc=" + bcc +
    "&subject=" + escape(subject) +
    "&body=" + escape(body);

  // POP UP EMAIL MESSAGE WINDOW
  window.location = doc;
}

Notice the usage of the escape() function when assembling the subject and body fields. It converts any non-alphanumeric character to its ASCII value (in hexadecimal notation). In this way, any ampersands and question marks in the subject or body fields do not confuse the browser, when it interprets the mailto: URL. Question mark and ampersands are used as delimiters in the mailto: URL, and using them in the message items themselves without escaping, will surely mess up the interpretation of the mailto: URL. Popping up the new mail message form is done by assigning the mailto: text to window.location:

window.location = doc;

Next: The Tool's Code

http://www.internet.com

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business


Produced by Yehuda Shiran and Tomer Shiran
All Rights Reserved. Legal Notices.
Created: October 9, 2000
Revised: October 9, 2000

URL: http://www.webreference.com/js/column70/7.html