Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Web
Expertise: Intermediate
Oct 14, 1998

Mailto Subject Changes

It's possible to create mailto links that include a subject line in addition to just the recipient's e-mail address, however, not all e-mail programs support this functionality. That said, to create a new e-mail message with the subject and CC fields filled in you can use a URL formatted like this:
 
mailto:someone@bigcorp.com?subject=Information&cc=anyone@othercompany.com
To get the functionality you're looking for, use JavaScript to assemble a URL like the one above from the user's selections on the form. Then set the window's location property to that URL. If this was a normal URL, the browser would display in the main window. However, because this is a mailto link, a new window is automatically opened for the e-mail message, while the current page remains visible.
 
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!--
function doMail() {
	var subj;
	var gourl;

	email = "someone@bigcorp.com";
	subj = document.forms.mailform.subject.options[document.forms.mailform.subject.selectedIndex].value;
	cc = "anyone@othercompany.com";
	gourl = "mailto:" + email + "?subject=" + subj + "&cc=" + cc;

	window.location = gourl;
}
//-->
</SCRIPT>

</HEAD>
<BODY>
<FORM NAME="mailform">
<SELECT NAME="subject">
	<OPTION VALUE="Info">Information request</OPTION>
	<OPTION VALUE="Tech. Support">Technical support</OPTION>
	<OPTION VALUE="Comments">Comment</OPTION>
</SELECT>
<INPUT TYPE="BUTTON" VALUE="Send Mail" OnClick="doMail()">
</FORM>
</BODY>
</HTML>

Boris Feldman
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date