问题
I'm new to javascript and the following code isn't working:
<script>
function sendMail()
{
var yourMessage = document.getElementById("message").value
var subject = document.getElementById("selectList").value
var mail="mailto:chrisgreg23@googlemail.com?subject="+subject+"&body="+yourMessage;
window = window.open(mail, 'emailWindow')
}
</script>
I just want a mail client window to open with the subject and body already done.
Help?
EDIT:
I've also tried this:
<script>
function sendMail()
{
var yourMessage = document.getElementById("message").value
var subject = document.getElementById("selectList").value
var mail="mailto:chrisgreg23@googlemail.com?subject="+subject+"&body="+yourMessage;
$(this).attr('href', mail);
}
</script>
Ive got that now, still not working.
回答1:
Your code should look like this instead:
<script>
function sendMail()
{
var yourMessage = document.getElementById("message").value;
var subject = document.getElementById("selectList").value;
document.location.href = "mailto:chrisgreg23@googlemail.com?subject="
+ encodeURIComponent(subject)
+ "&body=" + encodeURIComponent(yourMessage);
}
</script>
来源:https://stackoverflow.com/questions/21028939/mailto-using-javascript