You have many pages on your site. You want to get some feed back from your visitors about the page they are visiting. So, you include your email at the bottom of the page. The visitor comes along and reads the page. They have a comment and click on the email link you have provided. Their comments are specific to the page... or perhaps vaguely referenced. You have no idea what page they are talking about.
I will show you how to apply it to one page. Then I will show you how to apply it to many pages with a simple script within a page that calls an external text file.
The first thing that you should know about this script is that it uses the form tag plus input to create a button. When the button is clicked it fires the script. This is the way it works for all three methods. Here is the general layout of the form:
This is what it looks like:There is no code at present for the onClick event... that's next.
Use this method when you want to control how the email link is going to work for a single page and you want a subject line other than the title of the page where the link is located.
This is how the form will look for this method:
<form><input type="button" value="Write to me about the Inline Method" onClick="parent.location='mailto:email@example.com?subject=Inline Method of Email Subject'"></form>
onClick=" is the method that is used to fire the script.
parent.location='mailto: is the way in which you call the mail program up.
firstname.lastname@example.org this is where your email address goes.
?subject= This is how you add something to the subject line
Inline Method of Email Subject'" Place whatever text you want to appear in the subject line here.
Watch out for the double and single quote tags. They must be exact or the script will fail.
Single quotes nested (placed inside) of the double quotes.
Example: when you click on the button below the value line is on the button and the subject is entered on the email's subject line.
Use this script on each page that you want the subject line to reflect the title of the page. It comes in two parts: the script in the head of the document and, the form in the body
The script in the head of the document:
parent.location='mailto:place your email address here?subject=' +document.title
The form in the body of the document:
<input type="button" value="some text here" onClick="goingtoemail()">
What is happening here is that the onClick event in the form is calling to the script in the head of the document and asking to run the function called "goingtoemail()." This name can be almost anything you wish. It does not have to be called "goingtoemail."
After subject=' there is a space followed by a plus sign and the words document.title. This is how the title of the document is taken and placed in the subject line of the email.
Use this script if you want to do the same as above with many pages without all the work. You create a single external txt file and simply reference the txt file within the page.
First: create the text file. Simply open up your favorite text editor; notepad, notetab, HTML-kit; and write the following into it or copy and paste.
parent.location='mailto:your email address?subject=' +document.title
So, how do we get the page to call on the text file to load? Simple... place this code where you want the button to appear:
Of course you can name the text file anything you wish... just remember to reference the src file in the page with the same name. Below is the working example:
Hope that this helps you...
Author: Joseph Raymond
4th of April, 2001