Student name retrieval by JavaScript doesn't work on IE 11 - HTML5 only
Jan 18, 2018
By
Amir Shurrab
Hi Heroes,
I am using a JS code to retrieve the student name from the LMS. My code works on Chrome but not on IE11. I tested my scorm packages on Moodle. I am publishing for HTML5 only. I tried HTML5 with Flash fallback and it didn't work on IE 11 but worked on Chrome. Could you please check my code below and let me know if you could suggest any solution? I appreciate your help.
The code
//find out if html5 version is running
var path = window.location.pathname;
var html5 = path.includes("html5");
if (html5 = true) { //if html5 is running run this script
var player = GetPlayer();
function findLMSAPI(win) {
// look in this window
if (win.hasOwnProperty("GetStudentID")) return win;
// all done if no parent
else if (win.parent == win) return null;
// climb up to parent window & look there
else return findLMSAPI(win.parent);
}
var lmsAPI = findLMSAPI(this);
var myName = lmsAPI.GetStudentName();
var array = myName.split(',');
var newName = array[1] + ' ' + array[0];
player.SetVar("newName", newName);
} else { //if html5 isn't running (in other words flash) run this script
var player = GetPlayer();
var myName = lmsAPI.GetStudentName();
var array = myName.split(',');
var newName = array[1] + ' ' + array[0];
player.SetVar("newName", newName);
}
Many thanks,
Amir
6 Replies
I would try changing this line
if (html5 = true) { //if html5 is running run this script
to
if (html5 == true) { //if html5 is running run this script
Hi Amir,
I suffered a similar issue and solved it by reading this thread: https://community.articulate.com/discussions/articulate-storyline/username-from-an-lms-on-both-flash-and-html5
Hope it helps!
Hello All, I have a similar problem with Amir. I assume that new versions of Storyline broke the code above. This code is not working anymore..
Hi, this is the code I use and it works in IE 11 - html 5 only or with flash and it works in chrome.
var player = GetPlayer();
function findLMSAPI(win) {
if (win.hasOwnProperty("GetStudentID")) return win;
else if (win.parent == win) return null;
else return findLMSAPI(win.parent);
}
var lmsAPI = findLMSAPI(this);
var lmsName = lmsAPI.GetStudentName();
var commaIndex = lmsName.indexOf(',');
player.SetVar("UserName", ((commaIndex == -1) ? lmsName : lmsName.substr(commaIndex + 1).trim() + ' ' + lmsName.substr(0,commaIndex)));
Hi Nancy, I have found that your code works perfectly for me (HTML5 only) in all of IE 11, Chrome and Edge. I would be really grateful if you could show how to also get the user's first name in addition to the UserName.
Hi John, I have never done that so don’t know off the top of my head. When I get a chance I’ll see what I can come up with.
This discussion is closed. You can start a new discussion or contact Articulate Support.