Textarea Email with JavaScript URL Code

I am creating an application with WebView. You don't really need to know this, but this is the reason I need this question, no alternative methods.

Is there some way to script on the same web page as the textarea object and then by typing some JavaScript in the url, it will open the default mailer with user-entered text from the textarea as part of the message body.

Confused, I know, but I read it a couple of times.

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

+3


source to share


3 answers


Assuming it textarea

has id="ta1"

, this is what you want to type into the address bar:

javascript:location.href="mailto:a@b.com?body="+document.getElementById("ta1").value;

      

EDIT:



Follow the same steps as when the button is clicked:

<input type="button" onclick="location.href=&quot;mailto:a@b.com?body=&quot;+document.getElementById(&quot;ta1&quot;).value;" value="Send">

      

Works also in Android browser.

0


source


A mailto

link can include a default subject / post in it using url parameters.

<a href="mailto:someone@example.com?subject=My%20Subject&body=My%20message">

      



So, the best way to achieve what you want is to dynamically create a url based on the value of the input element <textarea>

. Then you can assign the url to the href

anchor tag attribute or directly window.location

.

Unfortunately this doesn't seem to work <form action="mailto:…">

, so you'll need JS.

+1


source


Just bind a listener to onkeyup

and onchange

for events <textarea>

, which triggers a function that creates the correct kind of reference mailto:

.

$("#sendMail").on("keyup change", function(){
    $(this).attr("href", "mailto:......");
});

      

You can specify the recipient, subject and body as follows:

<a id="sendMail" href="mailto:user@domain.com?subject=abcdef&body=bodyMessage">Send</a>

      

Then use some CSS to style the link to look like a button. For example.

#sendMail { display: block; background: #EEE; border: 1px solid #CCC; color: #000; }

      

0


source







All Articles