How to use internal js and call external js functions

There are  a few questions in our discussion how to call external js functions.

Maybe not complete while I summarized  4 ways using internal js or external js to create the same output. Attached include all 4 on different slides.

It’s a simple example to show different greetings depending on the local time, which many of us have used.

 Use “execute JavaScript”

1.      define variables and work on them directly in a linear way without function.

The codes will run line by line.

 2.    Use “execute JavaScript”- define variables and internal function.

The function will be called when we need it.

 

Use external js file

first we need to import the external js file; there are two ways:

-    Use executive javascript to import external file:

var head = document.getElementsByTagName('head')[0];

var script = document.createElement('script');

script.src = 'story_content/my_functions.js';// you need to put the js under story_content

script.type = 'text/javascript';

head.appendChild(script);

-    import the js in story.html and you need to embed the codes below between<head></head>

<script LANGUAGE="JavaScript1.2" SRC="story_content/MyJavaScriptFunctions.js" TYPE="text/javascript"></script>

The 1st way may easier for we don’t have to update the story.html codes every time we publish.

If there is no variable passing between external JS and storyline, that’s ok, like

function mygreeting(){ alert(“hello”); }

       

If there is variable we need to pass the values from js to storyline,

1.      Use return to pass the value from js to storyline

2.      Use general functions to pass a value instead of using return method;

 

1 Reply
Tracy Livingston

I have tried this and cannot get a button to trigger an external JS function. This should be a simple as executing javascript function from the button like this: fireTrigger(). I can fire the trigger from an HTML button in story_html5 file, but not from within my StoryLine so it's obviously connecting to my external.js file properly but not getting the call outside of StoryLine.