• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers

JavaScript in a button not functioning

Community Beginner ,
Feb 10, 2021 Feb 10, 2021

Copy link to clipboard

Copied

Hi,
I'm attempting to add JavaScript to a button so that when the trainee hits it, it will open an email.  My I.T. department has provided me with the language of the script. 

function () {
var subject = "Subject";
var body = "Body";
window.open('mailto:sampleemail@yahoo.com?subject=subject&body=body');
}

I placed it into the Script_Window and put the action as Execute JavaScript.  I then publish it as HTML, but when we get to the button and hit it, the training just continues on without opening the email.  I've done everything the user guide says and am told the script is correct.  What else am I missing?  

Thanks!

TOPICS
Advanced

Views

226

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Feb 10, 2021 Feb 10, 2021

The JS code is incomplete.  You've described a function but not given it a name, and then you haven't called the function.  Try this:

-------------------------------------

function myFunct () {
var subject = "Subject";
var body = "Body";
window.open('mailto:sampleemail@yahoo.com?subject=subject&body=body');
}

myFunct ();

-----------------------------------

However, using JS in this case was actually quite unnecessary (though it does make it easier to alter the subject and body text).  All you had to

...

Likes

Translate

Translate
Community Expert ,
Feb 10, 2021 Feb 10, 2021

Copy link to clipboard

Copied

The JS code is incomplete.  You've described a function but not given it a name, and then you haven't called the function.  Try this:

-------------------------------------

function myFunct () {
var subject = "Subject";
var body = "Body";
window.open('mailto:sampleemail@yahoo.com?subject=subject&body=body');
}

myFunct ();

-----------------------------------

However, using JS in this case was actually quite unnecessary (though it does make it easier to alter the subject and body text).  All you had to do was set the button to execute the Send Email To action and then enter this code in the field provided for that action:

-----------------------------------------

mailto:sampleemail@yahoo.com?subject=subject&body=body'

--------------------------------------

The result is the same.  When ever using JS it's usually best to make sure you are viewing the content via a web server, not just locally.  With Captivate, just use the Preview > HTML5 in browser option to see the content in a temporary web server environment.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 11, 2021 Feb 11, 2021

Copy link to clipboard

Copied

Thank you for your reply!  I really appreciate your suggestions.  JavaScript is a foreign language to me and I assumed my I.T. would provide what was needed. 

 

So, I'm trying to use the Send Email To option that you mentioned with the following:

mailto:sampleemail@yahoo.com?subject=Completed Endangered Children Training&body=This email certifies that I have completed the Endangered Children course with a minimum passing score of 80% on this date. 

 

But then I get an error message that "The email specified for 'Success Action' is invalid. Your changes cannot be saved."

 

I'm asking my I.T. for help, but they don't know Captivate.  And I don't know if this is a Captivate issue or what.  Do you have any additional thoughts you can share?  I really need this to work and appreciate the help!

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 11, 2021 Feb 11, 2021

Copy link to clipboard

Copied

I sent my previous reply too soon.  Instead of doing the Send Email To action, I used the JavaScript you provided and it worked! Thank you!

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 11, 2021 Feb 11, 2021

Copy link to clipboard

Copied

LATEST

Yes.  As I mentioned in my earlier reply, the JS makes it easier to edit and insert the kind of complex Subject or Body text that you wanted to have.  Technically, you can insert the same text using the other method with the Send Email action, but you'd need to make sure there are no spaces in the string of text because as soon as the web browser sees a space it concludes that the mailto link has ended.  The trick is to replace the spaces with %20 which then get replaced with spaces when the email opens.  But I agree that in your case the JS option is best.

 

Glad you got it sorted.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines