Forum Discussion

CommercialTr796's avatar
CommercialTr796
Community Member
11 months ago

Javascript stopped working overnight

Hello,

I have a javascript that is used to open a pre-populated email and it has been working fine for the last month. However, it is no longer working after the weekend. Whenever the code should execute, nothing happens, whereas previously an outlook email would appear.

Is the code wrong? Has one of the updates affected it?

Any ideas would be great.

 

Here is the code:

var player = GetPlayer();
var email = 'name@emailaddress.com';
var subject = 'Lesson Title';
var emailBody = 'Body of text in the email';
window.location.href='mailto:'+email+'?subject='+subject+'&body='+encodeURIComponent(emailBody);

  • Did you change or add any other javascript in the course or rename the variables?

    • CommercialTr796's avatar
      CommercialTr796
      Community Member

      Hi Phil,

      Thanks for the fast response.

      I haven't added/changed any of the javascript. The course itself has tons of branch offs and the javascript is copied and pasted numerous times with the only amendment being the email recipient. However, this wasnt a problem previously, it all worked fine.

      No rename to variables either. The trigger is set to execute the javascript when the timeline starts on the slide. Again, this was fine last week but nothing happens this week.

      I checked my defualt mail settings and they are set to outlook, so not sure what else to check.

      I have included pictures to help.

       

  • I think you have an error somewhere, the way javascript works in Storyline it is complied in one file, is one error in one trigger can stop all triggers after that point working. 

    You can try publishing and then running the user.js file through a checker like JS.hint

    • CommercialTr796's avatar
      CommercialTr796
      Community Member

      Thank you, i tried your recommendation and then thought to try the code in a new stroyline to see if this was the issue. So i opened a new storyline, added a submit button on slide 1 and then copied and pasted the same trigger to execute the javascript when the slide begins, on slide 2.

      It worked....So i take it the code is ok and the error seems to be the variables you mentioned before?

      I'm a little confused i must admit, but at least it narrowed the problem!

  • Nedim's avatar
    Nedim
    Community Member

    Your JavaScript code is very simple code intended to open the default email client on a user's device. It looks correct. I tested it in my project and it worked just fine. Just to make sure, I would only go to the Default apps manager to deselect and reselect the default email app.  

  • The error will be on one of the other slides in the javascript triggers. 

    If you publish the whole course run one of the triggers and watch the console it should tell you the line number in user.js where the error is, correct it and then try again. 

  • So i found my issue...and of course, it is a user issue!

    I was using the same javascript for 126 slides and I found a rogue comma that i'd accidentally added to one of them when editing slides for someone! 

    Thank you both for the replies, the part about javascript being compiled in one file was the key to me going down this route and finding the error.