mailto的使用技巧分享
时间:2021-10-27 09:15:46|栏目:JavaScript代码|点击: 次
mailto用法
如何使用mailto?
1)基本用法
<a href=mailto:sample@163.com>send email</a>
或者
<form action="mailto:sample@163.com">
</form>
mailto后跟的是收信人。
可使用参数列表
参数传递方式同页面之间传递值一样,可以使用查询字符串,也可以用form
querystring方式:
<a href="mailto:sample@163.com?subject=test&cc=sample@hotmail.com&body=use mailto sample">send mail</a>
form方式
<form name='sendmail' action='mailto:sample@163.com'>
<input name='cc' type='text' value='sample@hotmail.com'>
<input name='subject' type='text' value='test'>
<input name='body' type='text' value='use mailto sample'>
</form>
两种方式同样传递所有参数。
2)示例说明
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> Send Email </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<script>
Date.prototype.toString=function()
{
var d = new Date();
var ret = d.getYear();
var m = d.getMonth()+1;
ret+=m.length>1?m:'0'+m;
var date= d.getDate();
ret+=date.length>1?date:'0'+date;
return ret;
}
var initSubject='test'+new Date().toString(),initTo='sample@163.com',initCC='sample@hotmail.com',initBody='use mailto sample';
function submitHandler()
{
var subject = subText.value;
var to = toText.value;
var cc = ccText.value;
var body = bodyText.value;
mailTo.href="mailto:"+to+"?cc="+cc+"&subject="+subject+"&body="+body;
mailTo.click();
}
function init()
{
subText.value=initSubject;
toText.value=initTo;
ccText.value=initCC;
bodyText.value=initBody;
}
</script>
<style>
.label{font-weight:bold;postion:absolute;width:80px;}
.head{font-color:black;font-weight:bold;}
.bd{float:left;width:77px;font-weight:bold;}
</style>
<BODY onload="init()">
<div class="head">Use mailto Send Email</div>
<div>
<span class="label">Subject:</span><input id="subText" type="text" size=50 value="TM V14.2 Bug Fix Questions_20080221">
</div>
<div>
<span class="label">To:</span><input id="toText" type="text" size=50 value="">
</div>
<div>
<span class="label">CC:</span><input id="ccText" type="text" size=50 value="">
</div>
<div>
<span class="bd">Body:</span><textarea id="bodyText" rows=20 cols=100></textarea>
</div>
<input name="btSend" type="button" value="send email" onclick="submitHandler();">
<a href="mailto:" id="mailTo"></a>
</BODY>
</HTML>
成功者找方法,失败者找借口!
如何使用mailto?
1)基本用法
复制代码 代码如下:
<a href=mailto:sample@163.com>send email</a>
或者
复制代码 代码如下:
<form action="mailto:sample@163.com">
</form>
mailto后跟的是收信人。
可使用参数列表
to | 收信人 |
suject | 主题 |
cc | 抄送 |
bcc | 暗抄送 |
body | 内容 |
参数传递方式同页面之间传递值一样,可以使用查询字符串,也可以用form
querystring方式:
复制代码 代码如下:
<a href="mailto:sample@163.com?subject=test&cc=sample@hotmail.com&body=use mailto sample">send mail</a>
form方式
复制代码 代码如下:
<form name='sendmail' action='mailto:sample@163.com'>
<input name='cc' type='text' value='sample@hotmail.com'>
<input name='subject' type='text' value='test'>
<input name='body' type='text' value='use mailto sample'>
</form>
两种方式同样传递所有参数。
2)示例说明
复制代码 代码如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> Send Email </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<script>
Date.prototype.toString=function()
{
var d = new Date();
var ret = d.getYear();
var m = d.getMonth()+1;
ret+=m.length>1?m:'0'+m;
var date= d.getDate();
ret+=date.length>1?date:'0'+date;
return ret;
}
var initSubject='test'+new Date().toString(),initTo='sample@163.com',initCC='sample@hotmail.com',initBody='use mailto sample';
function submitHandler()
{
var subject = subText.value;
var to = toText.value;
var cc = ccText.value;
var body = bodyText.value;
mailTo.href="mailto:"+to+"?cc="+cc+"&subject="+subject+"&body="+body;
mailTo.click();
}
function init()
{
subText.value=initSubject;
toText.value=initTo;
ccText.value=initCC;
bodyText.value=initBody;
}
</script>
<style>
.label{font-weight:bold;postion:absolute;width:80px;}
.head{font-color:black;font-weight:bold;}
.bd{float:left;width:77px;font-weight:bold;}
</style>
<BODY onload="init()">
<div class="head">Use mailto Send Email</div>
<div>
<span class="label">Subject:</span><input id="subText" type="text" size=50 value="TM V14.2 Bug Fix Questions_20080221">
</div>
<div>
<span class="label">To:</span><input id="toText" type="text" size=50 value="">
</div>
<div>
<span class="label">CC:</span><input id="ccText" type="text" size=50 value="">
</div>
<div>
<span class="bd">Body:</span><textarea id="bodyText" rows=20 cols=100></textarea>
</div>
<input name="btSend" type="button" value="send email" onclick="submitHandler();">
<a href="mailto:" id="mailTo"></a>
</BODY>
</HTML>
成功者找方法,失败者找借口!