我有一个带有“下订单”按钮的网站,其上方是产品列表和文本框,允许我为每种产品设置数量。
单击按钮后,它会发回并计算每种产品需要多少,然后我将其放入一个大字符串中,前面带有“mailto:order@blah.com”。我现在想以某种方式让它在回发结束时自动弹出到客户端。
我尝试过 window.open,但这也会打开一个我想避免的新浏览器窗口。
按钮回发代码:
protected void btnPlaceOrder_Click(object sender, EventArgs e)
{
string url = "mailto:orders@blah.com?subject=New order from " + ddlSelectLocation.SelectedItem.Value;
url += "&body=Please raise a new order for the following items:" + Environment.NewLine;
foreach (GridViewRow row in grdOrder.Rows)
{
string model = row.Cells[0].Text;
int qty = 0;
TextBox txt = (TextBox)row.Cells[3].Controls[1];
if (int.TryParse(txt.Text, out qty))
{
if (qty > 0)
url += " - " + model + ": " + qty.ToString() + Environment.NewLine;
}
}
url += Environment.NewLine + "Many Thanks.";
Response.Write(url);
}
否则我将不得不编写大量客户端 JavaScript 代码:(
最佳答案
你能尝试这样的事情吗?
Page.ClientScript.RegisterStartupScript(this.GetType(),
"MAIL",
"window.open('" + url + "')",
true);
您必须确保字符串已正确转义...
关于javascript - 以编程方式实例化 mailto,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27530977/