Grab variable from launch URL using index_lms.html as the launch file

I have seen various threads about grabbing a variable from a parent URL and setting them to a variable that has been set/initiated in Storyline using JavaScript  such as:

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();

//storyline variables courseNumber and pathNumber must exist for this to work

player.SetVar("courseNumber", getQueryVal("courseNumber"));

player.SetVar("pathNumber",getQueryVal("pathNumber"));

However, in each of the examples I have seen and in my own testing, the only way I can get this to work successfully is to use the story.html file as the launching file, i.e.,

My question for the community is how can I still grab a variable from a parent URL, but using index_lms.html as the launching file? Do I need some variation of the example javascript I provided here?

5 Replies
Brandon Beaver

Thanks for your reply Phil! 

When I test using a URL something like the following:

https://devwww20.companyx.com/server1/brandon_js_test/story.html?courseNumber123456&pathNumber=1  - Note this is not an actual URL, but for illustration purposes

on our internal server, I get the variable values in Storyline without issue and can use them for what I need.

However, when I switch to using the URL like the following:

https://devwww20.companyx.com/server1/brandon_js_test/index_lms.html?courseNumber123456&pathNumber=1  - Note this is not an actual URL, but for illustration purposes

 so that it works in our LMS, I get null values in Storyline where the variable values should be.

I didn't expect there to be a difference based on whether I used story.html vs. index_lms.html, but for me there is and I need to use the index_lms.html for LMS communication.

I hope my question/clarification makes sense.

Christie Pollick

Hi, Brandon -- Glad to see you are working with Phil here! 

I just thought I'd stop in to share for those who may be unaware, that JavaScript is not something for which we'd be able to provide support, but there are lots of gurus like Phil here in the community who are usually more than willing to assist. And if you wanted to check it out, here is our JS Best Practices sheet. :)

Brandon Beaver

Hi Christie,

Thanks for the welcome and the link to the tip sheet. 

I'm hoping my second reply with clarification on my original request prompts more replies as my question is still outstanding.

I am thinking/hoping it is something simple that I'm overlooking or not doing and someone in the community with more expertise can help out!

- Brandon

Brandon Beaver

After doing some researching and talking with a few colleagues, I have figured out how to get the parameters from my launch URL when launching from index_lms.html (vs. using story.html) to pass into my course.

In the following code, I had to make just one tweak by adding the word parent, highlighted in my example in bold.  So, it was a matter of getting the path right in order to get the information from the URL to the course when using the index_lms.html URL.

function getQueryVal(variable) {   
var query = parent.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();

//storyline variables courseNumber and pathNumber must exist for this to work

player.SetVar("courseNumber", getQueryVal("courseNumber"));

player.SetVar("pathNumber",getQueryVal("pathNumber"));