Search code examples
javascripthtmlmailto

Email Textarea with JavaScript URL Code


I'm building an application with a WebView. You don't really need to know that but it is the reason why I need this question answered, no alternate methods.

Is there anyway to put some kind of script on the same web page as the textarea object, then after typing in some kind of JavaScript code in the URL, it will open the default mail program with the user entered text from the textarea as the body part of the message.

Confusing, I know, but read it over a couple times.

(Note: when I say popup the default mail program, I mean like the same method as mailto, when it opens in the default mail app)


Solution

  • With the assumption that the textarea has an id="ta1", is this what you are looking to type into your address bar:

    javascript:location.href="mailto:[email protected]?body="+document.getElementById("ta1").value;
    

    EDIT:

    Get the same action performed on button click:

    <input type="button" onclick="location.href=&quot;mailto:[email protected]?body=&quot;+document.getElementById(&quot;ta1&quot;).value;" value="Send">
    

    Works on Android stock browser too