Reputation: 5558
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)
Upvotes: 3
Views: 4769
Reputation: 7019
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="mailto:[email protected]?body="+document.getElementById("ta1").value;" value="Send">
Works on Android stock browser too
Upvotes: 1
Reputation: 7244
Just bind a listener to the onkeyup
and onchange
events for the <textarea>
that runs a function that creates the right kind of mailto:
link.
$("#sendMail").on("keyup change", function(){
$(this).attr("href", "mailto:......");
});
You can specific the receipient, subject, and body like this:
<a id="sendMail" href="mailto:[email protected]?subject=abcdef&body=bodyMessage">Send</a>
Then use some CSS to style the link to look like a button. E.g.
#sendMail { display: block; background: #EEE; border: 1px solid #CCC; color: #000; }
Upvotes: 0
Reputation: 5178
A mailto
link can include the default subject / message in it using URL parameters.
<a href="mailto:[email protected]?subject=My%20Subject&body=My%20message">
So, the best way to achieve what you want would be to build the URL dynamically based on the value of the <textarea>
input element. You can then assign the URL to the href
attribute of an anchor tag, or to window.location
directly.
Sadly, it doesn't look like <form action="mailto:…">
works, so you will need some JS.
Upvotes: 1