[英]Can I dynamically set the recipient of mailto: using only HTML and JavaScript depending on URL used to access the site?
[英]Is it possible to dynamically set the recipient of MAILTO: with only HTML and JavaScript?
我僅使用HTML和JavaScript創建表單,我希望通過更改MAILTO:地址或mailto:行的CC地址來動態設置POSTed表單的收件人。 這將完全由文本框的值確定。 此功能的目的是根據表單數據在下拉菜單中的選擇,需要將表單數據發送到其他管理器。 我已經在一個地方(http://javascript.internet.com/forms/multiple-mailer.html)看到了這一點,但是我的問題是我正在從JS數組填充下拉列表,當選中該列表時,它會填充一些文本字段,就像(http://www.webdeveloper.com/forum/showpost.php?p=984036&postcount=8)。 因此,我想做的是用我的下拉列表填充一個隱藏的文本輸入,並從中進行繪制以確定誰收到了電子郵件。
我應該注意,這是針對公司INTRAnet網站的,該網站缺少桌面電子郵件客戶端不是問題,並且IE是唯一可用的瀏覽器。 我沒有訪問服務器端技術的權限,所以mailto是我唯一的選擇,請不要浪費評論告訴我這是一個多么糟糕的主意,大聲笑。 謝謝!
思考?
要使用某些電子郵件地址打開郵件客戶端:
location = 'mailto:' + email_address;
要設置元素的href
,請首先使用document.getElementById
類a
元素來獲取它,然后設置href
屬性:
document.getElementById('someLink').href = 'mailto:' + email_address;
email_address
是一個字符串,其中包含適用的電子郵件地址-您可以將其替換為獲取下拉列表值的表達式:
document.getElementById('someLink').href = 'mailto:' + document.getElementById('dropdown').value;
對的,這是可能的。 我的表單中有一個類似於以下內容的選項框:
<td><select name="Division" id="Division" onChange="dirChange()" tabindex="3">
<option selected>Choose One</option>
<option value="Communications">Communications</option>
<option value="Legal Services">Legal Services</option>
</select> </td>
它指的是javascript函數:
function dirChange()
{
var i = document.all.Division.value;
switch (i)
{
case "Communications":
document.all.DeputyDirector.value = "Dave C.";
document.all.form.action = "mailto:Dave.C@xxxxx.com?subject=Form";
break;
case "Legal Services":
document.all.DeputyDirector.value = "Dixie P.";
document.all.form.action = "mailto:Dixie.P@xxxxxx.com?subject=Form";
break;
default:
document.all.DeputyDirector.value = "";
break;
}
}
然后,此javascript有助於在文本框中填寫所需的信息,並使表格通過電子郵件發送給所選人員。
<tr>
<td class="announcementText"> <span class="style12"><span class="style16"><span class="style31">*</span></span></span>Division Deputy Dir.: </td>
<td><input name="DeputyDirector" type="text" id="DeputyDirector" style="background-color:#cccccc; color:black; font-weight:bold; border:0; overflow:visible" size="38"></td>
</tr>
<form onChange="dirChange()" method="post" enctype="text/plain" name="form" id="form" onSubmit="return checkform(this);">
一旦選擇了通信部門,則客戶端的結果html為:對於文本框:
<input name="DeputyDirector" type="text" id="DeputyDirector" style="background-color:#cccccc; color:black; font-weight:bold; border:0; overflow:visible" size="38" value = "Dave C.">
並為形式:
<form onChange="dirChange()" method="post" enctype="text/plain" name="form" id="form" onSubmit="return checkform(this); action = "mailto:Dave.C@xxxxx.com?subject=Form">
或者他們為文本框選擇法律服務:
<input name="DeputyDirector" type="text" id="DeputyDirector" style="background-color:#cccccc; color:black; font-weight:bold; border:0; overflow:visible" size="38" value = "Dixie P.">
並為形式:
<form onChange="dirChange()" method="post" enctype="text/plain" name="form" id="form" onSubmit="return checkform(this); action = "mailto:Dixie.P@xxxxxx.com?subject=Form">
您只需使用Javascript將href
屬性設置為包含電子郵件地址的字符串即可。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.