如何使用JavaScript从文本区域中提取文本并将其放在Gmail的“撰写”字段中

时间:2015-07-15 08:09:16

标签: javascript html forms

我正在尝试发送用textarea写的文字发送到Gmail的撰写区。

问题是发送的输出如下

  

文本框=测试+邮件%21安培;倒计时= 690

我只想发送文字。

mailto链接到gmail。

这是我写的:

<html>
<head>
<script language="javascript" type="text/javascript">
function limitText(limitField, limitCount, limitNum) {
    if (limitField.value.length > limitNum) {
        limitField.value = limitField.value.substring(0, limitNum);
    } else {
        limitCount.value = limitNum - limitField.value.length;
    }
}
</script>
</head>

<body>

    <form  method="post" action="mailto:abc@gmail.com" name="myform">
<textarea name="textbox" onKeyDown="limitText(this.form.textbox,this.form.countdown,700);" 
onKeyUp="limitText(this.form.textbox,this.form.countdown,700);">
</textarea>

<br>
    <font size="1">(Maximum characters: 700)<br>
    You have <input readonly type="text" name="countdown" size="3" value="700"> characters left.</font>
    <input type="submit" value="Send Email" />
    </form>

</body>
</html>

1 个答案:

答案 0 :(得分:0)

这是最适合我的方式:

<form method="get" action="mailto:abc@gmail.com" name="myform" ENCTYPE="text/plain">
    <textarea name="body" onKeyDown="limitText(this.form.textbox,this.form.countdown,700);" onKeyUp="limitText(this.form.textbox,this.form.countdown,700);"></textarea>
    <br> <font size="1">(Maximum characters: 700)<br>
    You have <input readonly type="text" size="3" value="700"> characters left.</font>

    <input type="submit" value="Send Email" />
</form>

See my JSFiddle demo here