最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to pass variables to mailto method - Stack Overflow

programmeradmin0浏览0评论

I need to know if its possible to pass variables to the mailto: method.

I want to have something along the lines like this, so it opens a new email on outlook.

var email = "[email protected]"
var subject = "test"
window.href = "mailto:email?subject=subject"

Now i want to know if i can pass these variables. I don't care about the body of the email I just wanna have the email address and the subject line passed in. I can't ActiveXObject because my code is on the server side rather then the client side so it wont have permission to create objects. Or at least thats what i got from reading into opening outlook from javascripts.

I need to know if its possible to pass variables to the mailto: method.

I want to have something along the lines like this, so it opens a new email on outlook.

var email = "[email protected]"
var subject = "test"
window.href = "mailto:email?subject=subject"

Now i want to know if i can pass these variables. I don't care about the body of the email I just wanna have the email address and the subject line passed in. I can't ActiveXObject because my code is on the server side rather then the client side so it wont have permission to create objects. Or at least thats what i got from reading into opening outlook from javascripts.

Share Improve this question asked Sep 15, 2013 at 1:34 ZeRaTuL_jFZeRaTuL_jF 5922 gold badges4 silver badges20 bronze badges 7
  • 1 You replied to your own question. Just use window.location.href = "mailto:" + email + "?subject=" + subject;? – opatut Commented Sep 15, 2013 at 1:37
  • @opatut the problem is that i have tried the expression that you have, and all it does is print the actual +email+ into the email rather than what the variable contains. Do i need something special or am i missing something. – ZeRaTuL_jF Commented Sep 15, 2013 at 1:58
  • You are probably mixing or missing quotation marks. They are important! – opatut Commented Sep 15, 2013 at 2:02
  • @ZeRaTuL_jF: this works fine - jsfiddle/CUEEr – Qantas 94 Heavy Commented Sep 15, 2013 at 2:03
  • I guess I'm just missing typing something. I shall let you guys know when I get back to working on this. Thank you – ZeRaTuL_jF Commented Sep 15, 2013 at 2:22
 |  Show 2 more ments

1 Answer 1

Reset to default 2

You are missing some quotes somewhere. Make sure your quoting looks similar to this:

window.location.href = "mailto:" + email + "?subject=" + subject;
发布评论

评论列表(0)

  1. 暂无评论