spacer

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

home / experts / javascript / column70


The Mailtool

Developer News
OpenOffice 3.2 Lands Amid Critical Changes
Red Hat, IBM Firmly in KVM Virtualization Camp
Red Hat Talks Up Open Source Cloud Plans

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


The Network for Technology Professionals

Search:

About Internet.com

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

webref The latest from WebReference.com Browse >
Are Google's Language Translation Web Services Ready for Prime Time? · Installing and Using Meeplace, the Business Review CMS · Sending an HTML and Plain Text E-newsletter with ASP.NET, Part 2
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Top 10 Threats to Wireless Security · Poll: UC Uptake on the Rise · Review: Fluke AirCheck Wi-Fi Tester 1.0


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