Basic JavaScript Not Working

Jul 24, 2020

I've seen a few questions about JavaScript since the player changed in January, but I haven't seen anything that addresses really basic JavaScript commands. I tried to use the window.print(); command, but it doesn't do anything. 

I was testing this in Review (it's in a button trigger to execute JavaScript), and I wondered if that might be the issue. I published to CD and it still isn't working. If I can't get really basic JavaScript to function, I'm wondering if JavaScript is just no longer an available feature in Storyline 360. Am I missing something? 

7 Replies
Dave Cox

Hi Sarah,

I haven't tried the window.print command in quite some time, but I can assure you that Javascript works just fine in Storyline 360. I've programmed with it, and used it many times. (In fact, most of what happens under the hood in any StoryLine package is done with Javascript.)

I think it's more likely that there is a problem with your javascript. When something is wrong with javascript, it fails silently, and all that you will see is that is doesn't work. For troubleshooting Javascript problems, I recommend using lots of console.log statements, in your javascript so you can see just where the problem lies. 

Example: the statement: 

console.log("I'm on line 1");

will print the phrase "I'm on line 1" to print to the console.

Of course, now you need to be able to see what is printing to the console. A big secret about all browsers, is that they all have a console that can display special console messages and error messages. To view the console, press F12 on you keyboard to access the deveoper's panel. Locate and click on the console tab. This panel displays the console output.

Scattering these statements through out your code will help you see where the problem lies. If you put a statement like this before and after your print statement, and only the first one prints, then you know there is an error with your print statement.

I you still have trouble, getting this to work, I'm happy to help you troubleshoot if you can share your project, or a facsimile of your project.

Dave

Sarah Newman

Hi Dave,

I mentioned in my post that I published to Review and published to CD, so I was testing this in a published format. Also, I copied and pasted the code directly from Articulate's guide on JavaScript, and I tested it using playcode.io. It's functional JavaScript... but it doesn't do anything in my course. Any other ideas? I really need to be able to use JavaScript, as I need my learner to be able to print out a list of inputs from the course. The actual JavaScript I need to use is much more complex than the window.print command, so I don't know what to do if that simple command won't work. Any additional advice would be greatly appreciated.

Dave Cox

Hi Sarah,

I'm sorry, I missed the part about publishing to a CD. I haven't had a need to publish that way, so I haven't test it in that environment. I will have to do that and find out.

Let me ask this then. When you publish  to a CD, what format is published? Is it in and .exe, or is it in a web format? In order for javascript to work, your content must play in an internet browser, even if it is playing on a local machine. That is becuase Javascript is what is called an interpretive language, and the browser is what reads and interprets your javascript commands. 

What may work for you, is to publish your content for the web, and then publish the content on a CD, so that is plays in the user's browser. 

I'll do some testing tonight, and let you know what I find. Meanwhile, some other person here, may already have an answer for you.

Dave

This discussion is closed. You can start a new discussion or contact Articulate Support.