Skip to main content

How to call mail client on click of a button using javascript?

There are situations mail id from a text box needs to be populated in the outlook or any other mail client by calling mailto:

Here is the one way to do it.

<html>
    <head>
        <script>
        function sendMail(){
            var mailToId = document.forms[0].mailId.value;
            var mailto_link = 'mailto:'+mailToId;
            win = window.open(mailto_link,'tempWindow');
            if (win && win.open &&!win.closed) win.close();
        }
        </script>
    <head>

    <body>
        <form name= "mailForm" >
            <input type = "text" value="< Mail Id >" name="mailId">
            <input type = "button" value="Send Mail "onclick= "sendMail()" >
        </form>
    </body>
</html>

Here is the link which talks about mailto syntax : http://www.ianr.unl.edu/internet/mailto.html


Blogged with Flock

Comments

Anonymous said…
The only thing I see wrong with that, code is that it doesnt actually close the window. and your left with the window open.

Popular posts from this blog

Working for google can be mind blogging

Here are some interesting questions that Google asks you when you try a position in Google . I am not sure how legitimate they are, but here are a few for your amusement 1. How many golf balls can fit in a school bus? 2. You are shrunk to the height of a nickel and your mass is proportionally reduced so as to maintain your original density. You are then thrown into an empty glass blender. The blades will start moving in 60 seconds. What do you do? 3. How much should you charge to wash all the windows in Seattle? 4. How would you find out if a machine’s stack grows up or down in memory? 5. Explain a database in three sentences to your eight-year-old nephew. 6. How many times a day does a clock’s hands overlap? 7. You have to get from point A to point B. You don’t know if you can get there. What would you do? 8. Imagine you have a closet full of shirts. It’s very hard to find a shirt. So what can you do to organize your shirts for easy retrieval? 9. Every man ...

How to deselect all the selection in a select ( combo ) box?

In a HTML page sometimes we may have to deslect all the selection in a select control of html. but as a user we can't do anything. But using Javascript programatically we can achieve this. Here is the sample code in Javascript. function clearSelect( selectObj ){ for (var i = 0; i selectObj .options[i].selected = false; } } note: we need to pass the select object as a parameter to this function. the alternative to this code is function clearSelect( selectObj ){ selectObj.selectedIndex = -1; }