Execute Javascript Trigger
May 14, 2014
I've added 4 buttons in Storyline to show some examples of JavaScript in e-Learning.
Each button has a trigger to execute the Javascript code (which I got directly from w3schools).
They are labeled:
- Now
- Browser
- Hello
To execute these corresponding JavaScript codes (onClick):
- Display current date and time
- Print the current page
- Displayer user's browser version
- Display a Hello message after 3 seconds
Codes are provided in attachment.
I published to HTML and viewed the page but none of the JavaScript is executing.
So I'm reaching out for help... is there a step I'm missing; does this need to be loaded to an LMS to function, or something else?
I've also noticed that my sample to launch EMail when clicking a button doesn't work either.
Thanks for any tips you can provide,
christine
8 Replies
Hi Christine, you might want to take a look at these basic JavaScript examples to get a better idea of how the JS code should be structured in Storyline and how to use the GetPlayer(), SetVar() and GetVar() JavaScript methods that are supported in Storyline. http://www.articulate.com/support/storyline/javascript-best-practices-and-examples
YES to what Christine said.
You will notice when you look at it that when you put the Javascript into the triggers you are not supposed to put all that stuff in there like headers etc. Out of the code you have, all you need is actual Javascript commands.
For example: that first one for date. You are going to need something that looks like this:
var player = GetPlayer();
player.SetVar("sDate",Date());
BUT, you are going to need to establish a variable in Storyline called sDate and it is going to give you a date that you might not expect. It gives a long verbose date that includes timezone UTC etc.
You'll need to look up other Javascript for formatting.
One more thing. If you are viewing your published output locally, JavaScript will not work. You need to upload this to your webserver or dropbox.
Hope this helps,
Alex
@Alexandros: What you mean to say is true, but you are not saying it correctly.
You can PUBLISH it to your drive and view it and the Javascript will work. I do it all the time.
What won't work is the PREVIEW mode. Articulate has not set up the preview feature to be able to run Javascript.
For what it's worth, here is a quick test with your JavaScript snippets. I did remove the HTML tags and only used the JavaScript functions.
Michael,
This is exactly what I would like to include in my sample...
I've tried to follow your lead and remove the extra coding from the scripts but I think that I'm still missing something.
For example, I changed the code for the first button to execute this code:
function myFunction() {
document.getElementById("demo").innerHTML = Date();
}
My SuperHero!
Thank you so much Michael!
This discussion is closed. You can start a new discussion or contact Articulate Support.