The Internet Connection

By Michael Sauers

Send an E-mail about "This Page" with JavaScript

Web page creators can perform some great little tricks with just a few lines of JavaScript. The one described here creates a link on the page that generates an e-mail message with a subject line specified by you, text in the body specified by you and including the URL of the page with the link.

Please test this. It works in the newest versions of Netscape Navigator and Microsoft Internet Explorer, but may not work in older versions of the two major browsers or in other browsers.

   <script language="javascript">
   <!--
   function SendEMail()
   {
         var sRef = "mailto:&subject=
this is the subject&body=this appears in the body"+location.href;
         location.href = sRef;
   }
    //-->
   </script>
   <A href="javascript:SendEMail()">
send this link to a friend.</a>

Capital letters and spacing in the JavaScript code must be typed as they appear above for the JavaScript to work.

Lines 1 through 9 of the code should be placed in the head of your document. Line 10 goes in the body of the document where you want the link to appear.

Lines 5 and 6 must be typed in as one line without any line break or word wrapping.

Replace "this is the subject" with the text you want to appear in the subject line of the e-mail message.

Replace "this appears in the body" with the text you want to appear in the body of the message, to be followed by the URL and title of the document.

You may want to replace "send this link to a friend" with your own text.


Back to Table of Contents To BCR Home Page