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

Software way of milking cow: ( I got this through mail... Intersting ) Softwarism:(Ultimate....) If Client has 2 cows and u need to milk them 1 .. First prepare a document when to milk them (Project kick off) 2 .. Prepare a document how long you have to milk them (Project plan) 3 .. Then prepare how to milk them (Design) 4 .. Then prepare what other accessories are needed to milk them (Framework) 5 .. Then prepare a 2 dummy cows (sort of toy cows) and show to client the way in which u will milk them (UI Mockups & POC) 6 .. If client is not satisfied then redo from step 2 7 .. You actually start milking them and find that there are few problem with accessories. (Change framework) 8 .. Redo step 4 9 .. At last milk them and send it to onsite. (Coding over) 10. Make sure that cow milks properly ( Testing) 11. Onsite reports that it is not milking there. 12. You break your head and find that onsite is trying to milk from bulls 13. At last onsite milk them and send to client (Testing) 1...

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; }