a001index and URL Variables

andrew-robertson
andrew-robertson Community Member Posts: 185 ☆ Superstar ☆
Hello Rockstars,

So I am playing with the notion of using a user's specific geolocation based on one of the many APIs out there. I got it working nicely in a test module but when we went to a regional test it all appeared to come out of one location - which makes sense because of our network infrastructure.

While poking through the developer tools of the web browser, I noticed that our LMS is sending URL level variables on the module's first load. For example:

https://<myLMSdomain>/foo/bar/en/Andrew/a001index.html<b class="Bold">?localserver=ABCD</b>

Is there anyway to pull that variable using a script inside of Lectora software (e.g. JavaScript action) or must I be inserting my JavaScript code into the a001index.html file and passing the variable through client side storage.
Andrew R.
Developing content since 2010 using a mixed bag of tools.

Answers

  • nmaharaj
    nmaharaj Moderator Posts: 10 eLearning ROCKSTAR Stage Manager
    Yes, essentially you could have Lectora load a script to capture that data and assign it to a variable, then you would be able to access that variable in Lectora.
  • andrew-robertson
    andrew-robertson Community Member Posts: 185 ☆ Superstar ☆
    Great thank you @nmaharaj , however, how do I put that reference in the a001index.html file? I cannot find out where to put it.
    Andrew R.
    Developing content since 2010 using a mixed bag of tools.
  • andrew-robertson
    andrew-robertson Community Member Posts: 185 ☆ Superstar ☆
    Bump. Sorry to be one of those guys. Is there any way to add stuff to the a001index.html file without actually having to publish, extract the zip, edit the a001index.html file, and then recompress the package?
    Andrew R.
    Developing content since 2010 using a mixed bag of tools.
  • wheels
    wheels Florida USACommunity Member, Administrator, Moderator, Rockstar Manager Posts: 574 eLearning ROCKSTAR Admin Team
    edited April 29, 2021
    Try adding a title level On Show -> Run JavaScript action to fill a variable called ServerLocation


    // assuming you have a Lectora Variable named ServerLocation
    var urlParams = new URLSearchParams(myTop.location.search);
    if (urlParams.has('localserver'))
      VarServerLocation.set(urlParams.get('localserver'))
  • andrew-robertson
    andrew-robertson Community Member Posts: 185 ☆ Superstar ☆
    I'll give this a whirl and report back.
    Andrew R.
    Developing content since 2010 using a mixed bag of tools.