The javscript below is working fine; the email window opens with the addressee filled in and a subject line. The point of sending this email from inside the course is to send the value of a variable. Will someone who knows javascript add the correct lines to do this?
The variable is a text entry variable with 50- 100 words typed by the learner.
var email="yourAddress@email.com"; var subject="subject line"; var body_start="How you want to begin your body."; var mailto_link='mailto:'+email+'?subject='+subject+'&body='+body_start; win=window.open(mailto_link,'emailWin');
Matthew, your tutorial is so helpful! I was already playing with the script but it wasn't making a lot of sense.
I want to do one more thing and am having trouble making it work. Can you help?
I want to include the learner's username in the email body.
In my SL2 file, I have a text entry (essay question) with a variable called "words" that captures the user's input. (I also have a variable on the same screen called "Counted" that captures the number of "words" and when user presses a button it displays a count. The client wants 50-100 words only.)
I have another variable called "username" where SL asks the user to type in their company username into a text entry box on a previous screen.
You'll want to test the published output by uploading it to the intended environment vs. testing it locally. The reason being that the browser security for testing content locally could be interfering and you can see a bit more information about that here.
If you don't have a web server to test on, you could also look at using Tempshare or Amazon S3 as mentioned in that article and here are some more detailed directions for Amazon S3.
YAY! It works. I added a space before 'submitted these things that he/she learned in Module 1:' to separate the user name from the sentence. THANK YOU SO MUCH.
One more question, Matthew: How do I eliminate the new browser window opening but still execute the mail_to? It opens on top of the course window and may confuse the learner. Most of our learners will have Outlook.
Thanks. You are right, adding win.close(); tried to close the current window, not the new one. I tried window.location.href and it opened only my email, without the Outlook popup warning, and without a new browser tab. Great...but the email is blank and does not pull in the data from the variables.
Do you think this would work, if I had the script right?
var player = GetPlayer(); var email = 'roc@company.com'; var getwords = player.GetVar('words'); var subject = 'ROC User Input for Module 1'; var getusername = player.GetVar('username'); var emailBody = getusername + ' submitted these things that he/she learned in Module 1:' + '\n' + getwords; var window.location.link = 'mailto:' + email + '?subject=' + subject + '&body=' + encodeURIComponent(emailBody); window.location.href = "mailto:roc@company.com";
Does anyone have an example of a multi line email body or a clear idiot proof guide of what means what and how to bracket text vs variable in the layout?
Thanks, that was my first thought but I keep getting a bad request (400) when i put any html in the body, apparently the way i am sending the emails (it was set up by a guy in my office) doesn't like < > brackets so html is out :(
A-mazing! So very very close now. The line breaks don't seem to be working though. Last question, swear to god, is there like a tab command or something so i can even it up a bit. I'm not finding anything.
11 Replies
Matthew, your tutorial is so helpful! I was already playing with the script but it wasn't making a lot of sense.
I want to do one more thing and am having trouble making it work. Can you help?
I want to include the learner's username in the email body.
In my SL2 file, I have a text entry (essay question) with a variable called "words" that captures the user's input. (I also have a variable on the same screen called "Counted" that captures the number of "words" and when user presses a button it displays a count. The client wants 50-100 words only.)
I have another variable called "username" where SL asks the user to type in their company username into a text entry box on a previous screen.
Here's my code:
var player = GetPlayer();
var email = 'roc@company.com'
var getwords = player.GetVar('words');
var subject = 'ROC User Input';
var getusername = player.GetVar('username');
var emailBody = 'getusername' + submitted these things that he/she learned in Module 1:' + '\n' + getwords;
var mailto_link = 'mailto:' + email + '?subject=' + subject + '&body=' + encodeURIComponent(emailBody);
win = window.open(mailto_link, 'emailWin');
I've published this and tested on my local hard drive as HTML5 and Flash. The username won't pull in. Any help is appreciated! Thank you.
Jill,
You'll want to test the published output by uploading it to the intended environment vs. testing it locally. The reason being that the browser security for testing content locally could be interfering and you can see a bit more information about that here.
If you don't have a web server to test on, you could also look at using Tempshare or Amazon S3 as mentioned in that article and here are some more detailed directions for Amazon S3.
YAY! It works. I added a space before 'submitted these things that he/she learned in Module 1:' to separate the user name from the sentence. THANK YOU SO MUCH.
Thanks, I will do that Ashley!
One more question, Matthew: How do I eliminate the new browser window opening but still execute the mail_to? It opens on top of the course window and may confuse the learner. Most of our learners will have Outlook.
Thanks. You are right, adding win.close(); tried to close the current window, not the new one. I tried window.location.href and it opened only my email, without the Outlook popup warning, and without a new browser tab. Great...but the email is blank and does not pull in the data from the variables.
Do you think this would work, if I had the script right?
var player = GetPlayer();
var email = 'roc@company.com';
var getwords = player.GetVar('words');
var subject = 'ROC User Input for Module 1';
var getusername = player.GetVar('username');
var emailBody = getusername + ' submitted these things that he/she learned in Module 1:' + '\n' + getwords;
var window.location.link = 'mailto:' + email + '?subject=' + subject + '&body=' + encodeURIComponent(emailBody);
window.location.href = "mailto:roc@company.com";
Does anyone have an example of a multi line email body or a clear idiot proof guide of what means what and how to bracket text vs variable in the layout?
According to this (http://esprima.org/demo/validate.html) there's an unexpected string on line 13 but i'm not even sure what that means
Hi Bruce,
I would try building the body like an html table.
Try something like this:
var body = '<table><tr><td>Q</td><td>WordProcessing</td><td>Spreadsheets</td><td>Email</td></tr>';
body += '<tr><td>1</td><td>'+WP01+'</td><td>'+SSQ01+'</td><td>'+EMQ01+'</td></tr>';
body += '<tr><td>2</td><td>'+WP02+'</td><td>'+SSQ02+'</td><td>'+EMQ02+'</td></tr>';
body += '<tr><td>3</td><td>'+WP03+'</td><td>'+SSQ03+'</td><td>'+EMQ03+'</td></tr>';
.
.
.
body += '<tr><td>Total Score=</td><td>'+TOTALscore+'</td></tr></table>';
Thanks, that was my first thought but I keep getting a bad request (400) when i put any html in the body, apparently the way i am sending the emails (it was set up by a guy in my office) doesn't like < > brackets so html is out :(
Hi Bruce,
Take a look at the attached text file.
A-mazing! So very very close now. The line breaks don't seem to be working though. Last question, swear to god, is there like a tab command or something so i can even it up a bit. I'm not finding anything.
This discussion is closed. You can start a new discussion or contact Articulate Support.