spacer

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

home / experts / javascript / column70


The Mailtool

Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs

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, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint


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