Forum Discussion
Passing variables from LMS into an embed
I think I could find a way, not sure if this would help anyone but in case that someone faces a similar challenge.
The downside with this approach is, that the webobject and the scorm package have to be uploaded to the same domain in order to use localStorage.
First step is creating the html file for the iframe in Rise. The html file would contain the follwoing script:
<script>
var iframeUserName = window.localStorage.getItem('localUserName');
</script>
After uploading the html file to the server I'll paste the url to Rise (Multimedia->Embed) and then publish the course for LMS.
I unzip the scorm package and open the index.html. Inside the scormcontent folder I go to the very end of the file and paste the following snippet before </body>:
<script>
/* this function looks for the lms API */
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);
// get the user ID and user name from the LMS
var userID = lmsAPI.GetStudentID();
var userName = lmsAPI.GetStudentName();
// store the user name and user ID to localStorage
window.localStorage.setItem('localUserName', userID);
window.localStorage.setItem('localUserID', userName);
</script>
It is important that the parameters in setItem match getItem from the iframe match.
That is my current approach. Any comment, improvement, idea is highly appreciated.
- Crystal-Horn4 years agoStaff
Thanks so much for your contribution, Fabian!
Related Content
- 12 months ago
- 12 months ago
- 12 months ago
- 12 months ago
- 12 months ago