javascript 如何从操作方法中触发mailto url
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17445443/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to fire mailto urls from action method
提问by Suraj
I am a beginner in MVC. I want to develop an action method in MVC which fires Mailto:?body=body goes here.&subject=test subject
and so the default mail client will automatically populate the email for the user. Right now I have List<String>
which contain mailto:
urls.
我是 MVC 的初学者。我想在 MVC 中开发一个动作方法,它会触发Mailto:?body=body goes here.&subject=test subject
,因此默认邮件客户端将自动为用户填充电子邮件。现在我有List<String>
哪些包含mailto:
网址。
Please, if you have any experience or demo code it will be helpful to me. Thanks in advance.
请,如果您有任何经验或演示代码,它将对我有所帮助。提前致谢。
采纳答案by Suraj
My ActionMethod
我的行动方法
[HttpPost]
public JsonResult emailTemplate()
{
List<String> str = new List<String>();
str.Add("Mailto:?body=Hello1&subject=test subject1");
str.Add("Mailto:?body=Hello2&subject=test subject2");
return Json(str);
}
JavaScript Function in view
视图中的 JavaScript 函数
function SendMailClicked() {
$.ajax({
type: "POST",
url: "/Home/emailTemplate",
//data: "{'ReviewComponentIds':'1,2,3'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
jQuery.each(response, function () {
window.location.href = this + '\n';
});
},
failure: function (errMsg) {
alert('failure');
}
});
}
回答by Bastien D
try this :
试试这个 :
window.location.href = "mailto:[email protected]";
with body
与身体
window.location.href = "mailto:[email protected]?body=yourBody";
Event with jquery
事件与 jquery
$('button').on('click', function(){
window.location.href = "mailto:[email protected]?body=yourBody";
});