CODEDIGEST
Home » CodeDigest
Search
 

Technologies
 

Open an Outlook window from JavaScript with Pre-populated Subject and Body
Submitted By Satheesh Babu B
On 2/12/2009 7:44:10 AM
Tags: CodeDigest,JavaScript,Outlook  

Open an Outlook window from JavaScript with Pre-populated Subject and Body

 

Sometimes, we will get a requirement where we need to open an outlook window from JavaScript with some pre-populated data in the subject and body. For example: Sending an article or code snippet that you find interesting on a site to your friend.

 

The below code snippet will open an outlook window with a pre-populated subject and body that contains the page title and URL of the page in the next line.

 

<head runat="server">

    <title>Email This Code Snippet</title>

    <script language="javascript">

    function TriggerOutlook()

    {        

        var body = escape(window.document.title + String.fromCharCode(13)+ window.location.href);       

        var subject = "Take a look at this cool code snippet from CodeDigest.Com!!";

                        window.location.href = "mailto:?body="+body+"&subject="+subject;               

            }   

    </script>

</head>

<body>

    <form id="form1" runat="server">

    <div>

        <a href="#" onclick="TriggerOutlook()">Email this Codesnippet</a>

    </div>

    </form>

</body>

</html>

 

Once the user clicks the link "Email this Codesnippet" it will trigger an outlook window with a pre-populated subject and body.

Do you have a working code that can be used by anyone? Submit it here. It may help someone in the community!!

Recent Codes
  • View All Codes..