I would like to pass a userName and userID into StoryLine from the story.html page.
I tried created a javaScript function in an external js file and loading it into the story.html page. and then calling the function from a trigger inside the story file. I tried using the GetPlayer() and player.SetVar() methods but I couldn't get the variable to update inside the story file.
Just to clarify. Are you thinking passing the userName and ID INTO Storyline? Like story.html?userName=Joe&userID=1234. Or are you wanting to pass from Storyline to another mechanism?
Sure can. It really depends on your context though. One way is through an AJAX post request. The above is a good way to pass in a temporary session token that Storyline could use to retrieve values through the post request.
I've been working on a test module that calls values in a javascript trigger, but it is not working. Can anyone review this? Any suggestions?
JavaScript JS(1) does not seem to be working. JS(2) does seem to be working.
=============================
JS(1) triggered when timeline starts:
var player = GetPlayer(); player.SetVar("UniqueID", "#!#UNIQUEID#!#"); player.SetVar("ResponseURL", "#!#RESPONSEURL#!#");
=============================
JS(2) triggered when pass quiz (status=passed)
var player = GetPlayer(); var status = player.GetVar("Status"); var uniqueid = player.GetVar("UniqueID"); var responseurl = player.GetVar("ResponseURL");
// ajax start var xhr; if (window.XMLHttpRequest) xhr = new XMLHttpRequest(); // all browsers else xhr = new ActiveXObject("Microsoft.XMLHTTP"); // for IE
var url = responseurl + '?status=' + status + '&uniqueid=' + uniqueid; alert("opening: " + url); xhr.open('GET', url, false); xhr.onreadystatechange = function () { //4: request finished and response is ready // 200: “OK” else 404: “Page not found” if (xhr.readyState===4 && xhr.status===200) { // you can uncomment the following line to test if the vars are passed // a pop-up will be displayed //alert(xhr.responseText); } } xhr.send(); // ajax stop return false;
I am trying this with an objective to make the player switch to a particular slide based on two variables passed through the URL. I do not have access to any web server. So, I have to test it locally. But, so far, I am unable to do it. Can you please suggest a way I can test it locally? Also, I would prefer working with a single variable instead of 2. Can you please modify the code accordingly. I have very little idea of Javascript.
Hi there, time for a Java for Dummies question as I have never used it before. I tried to follow it from here, but I'm a little unsure (and of course it didn't work for me!). I want to show the User Name in my Storyline course from the Storyline, I have set up the following:
Text on screen: %userName%
Trigger: Execute Java Script when timeline starts, and in the java script I have the following:
function getQueryVal(variable) { var query = window.location.search.substring(1); var vars = query.split('&'); for (var i = 0; i < vars.length; i++) { var pair = vars[i].split('='); if (decodeURIComponent(pair[0]) == variable) { return decodeURIComponent(pair[1]); } } } var player=GetPlayer(); player.SetVar("userName", getQueryVal("userName"));
I have zero idea on what the above means, but perhaps someone can help me out? I have attached my Storyline 360 file also, and am using SuccessFactors LMS.
18 Replies
Hi David,
Just to clarify. Are you thinking passing the userName and ID INTO Storyline? Like story.html?userName=Joe&userID=1234. Or are you wanting to pass from Storyline to another mechanism?
I was thinking of reading them via javascript. But would use whatever works.
Hi David,
How is the data going to get into the Storyline player?
I would pass them in from a Coldfusion backend - they could be embedded in HTML - or Javascript, or could be passed on the URL.
Thanks for your help, David
Give this a shot in a javascript trigger:
function getQueryVal(variable) {
var query = window.location.search.substring(1);
var vars = query.split('&');
for (var i = 0; i
var pair = vars[i].split('=');
if (decodeURIComponent(pair[0]) == variable) {
return decodeURIComponent(pair[1]);
}
}
}
var player=GetPlayer();
//storyline variables userName and userID must exist for this to work
player.SetVar("userName", getQueryVal("userName"));
player.SetVar("userID",getQueryVal("userID"));
//using this setup, the URL construction below should work
//http://yourURL/story.html?userName=Joe Johnson&userID=1234
Thank you Steve. It worked exactly as you said. I appreciate your help.
Steve, you seem like the guy who can help with my earlier post - http://community.articulate.com/forums/p/36818/198393.aspx#198393
Thanks!
I see you were able to get some assistance here (well, you're other post) Bradley Steve is awesome!
Hello,
I'm having trouble getting this to work. Maybe I'm misunderstanding.
I have two variables added to my Storyline: userID and userName.
I have the following JavaScript executing when the timeline starts:
function getQueryVal(variable) {
var query = window.location.search.substring(1);
var vars = query.split('&');
for (var i = 0; i
var pair = vars[i].split('=');
if (decodeURIComponent(pair[0]) == variable) {
return decodeURIComponent(pair[1]);
}
}
}
var player=GetPlayer();
//storyline variables userName and userID must exist for this to work
player.SetVar("userName", getQueryVal("userName"));
player.SetVar("userID",getQueryVal("userID"));
Also, I have two variable references on the first slide to display: %userName% and %userID%
Finally, I have uploaded the published files to http://capabilityx.ca/dev/story.html
However, When I go to the URL - http://capabilityx.ca/dev/story.html?userName=Joe Johnson&userID=1234
I don't see Joe Johnson and 1234 in my variable references on the first slide.
Any help would be appreciated. I've uploaded my .story file.
Thanks,
Mark
Hah. Pesky less than sign. The forum swept away part of the code. That's making your function error. Let's see if it works this time:
Nope. Forum still swept out that symbol. The for(var i=o; i is less than vars.length; i++){ is what's missing. I've attached one that should work.
Thanks Steve! That was it.
I would have responded earlier but I didn't see an email saying the post had been replied too.
Much appreciated.
Mark
Glad that Steve was able to help you out Mark
Unfortunately you have to subscribe to the thread each time that you respond. It's a side effect of our current spam control.
Steve - great recommendation!
My crew is very security sensitive. Is there a way to do this without passing the variables through the URL?
Howdy -
Sure can. It really depends on your context though. One way is through an AJAX post request. The above is a good way to pass in a temporary session token that Storyline could use to retrieve values through the post request.
It all depends on the use case and the system.
*** JAVASCRIPT AND STORYLINE ***
I've been working on a test module that calls values in a javascript trigger, but it is not working. Can anyone review this? Any suggestions?
JavaScript JS(1) does not seem to be working. JS(2) does seem to be working.
=============================
JS(1) triggered when timeline starts:
var player = GetPlayer();
player.SetVar("UniqueID", "#!#UNIQUEID#!#");
player.SetVar("ResponseURL", "#!#RESPONSEURL#!#");
=============================
JS(2) triggered when pass quiz (status=passed)
var player = GetPlayer();
var status = player.GetVar("Status");
var uniqueid = player.GetVar("UniqueID");
var responseurl = player.GetVar("ResponseURL");
// ajax start
var xhr;
if (window.XMLHttpRequest) xhr = new XMLHttpRequest(); // all browsers
else xhr = new ActiveXObject("Microsoft.XMLHTTP"); // for IE
var url = responseurl + '?status=' + status + '&uniqueid=' + uniqueid;
alert("opening: " + url);
xhr.open('GET', url, false);
xhr.onreadystatechange = function () {
//4: request finished and response is ready
// 200: “OK” else 404: “Page not found”
if (xhr.readyState===4 && xhr.status===200) {
// you can uncomment the following line to test if the vars are passed
// a pop-up will be displayed
//alert(xhr.responseText);
}
}
xhr.send();
// ajax stop
return false;
Hi Steve,
I am trying this with an objective to make the player switch to a particular slide based on two variables passed through the URL. I do not have access to any web server. So, I have to test it locally. But, so far, I am unable to do it. Can you please suggest a way I can test it locally? Also, I would prefer working with a single variable instead of 2. Can you please modify the code accordingly. I have very little idea of Javascript.
Thanks in advance.
Sumit
Hi there, time for a Java for Dummies question as I have never used it before. I tried to follow it from here, but I'm a little unsure (and of course it didn't work for me!). I want to show the User Name in my Storyline course from the Storyline, I have set up the following:
Text on screen: %userName%
Trigger: Execute Java Script when timeline starts, and in the java script I have the following:
function getQueryVal(variable) {
var query = window.location.search.substring(1);
var vars = query.split('&');
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split('=');
if (decodeURIComponent(pair[0]) == variable) {
return decodeURIComponent(pair[1]);
}
}
}
var player=GetPlayer();
player.SetVar("userName", getQueryVal("userName"));
I have zero idea on what the above means, but perhaps someone can help me out? I have attached my Storyline 360 file also, and am using SuccessFactors LMS.
This discussion is closed. You can start a new discussion or contact Articulate Support.