The Mailtool: Writing a Script-Based Tool - Doc JavaScript

The Mailtool

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:

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: