Storyline 3/360 Change Variable on Browser Window Close

May 05, 2019

I am currently working on quite a unique path that a learning would follow on Storyline. As part of this is it essential that we determin if a user has closed their browser or exited a course early.

I have read several discussions where we can prompt a user before closing, using the event onunload which I can get working but I believe the connection to the LMS has stopped and Storylines own Unload function has ran before anything inside the course will run.

I am wondering if anyone has seen this before. If it helps I have set up limited attempts on a course and a timed lockout between each attempt. I am trying to make it so that if the user closes the window it counts as an attempt. (Adjusts a variable).

I believe I could also make it work if I could revert the user to the first slide when they revisit but keep all variables (which the player reset option doesnt do).

Hope someone has an idea :)

 

Edit: I think this could be done by adding code to change the variable in one of the JS files, inside the Unload function but would prefer to do this from the course itself as it will cover a large quantity of test and asking designers to edit a .js file could cause more issues.

3 Replies
Ben McKinstry

I am so close with this one.

I have added the following code to the slide layouts that i need a variable to update on close

window.addEventListener('beforeunload', function() {
var x = 2000;
var a = (new Date()).getTime() + x;

WriteToDebug("WRITTEN WRITTEN WRITTEN WRITTEN WRITTEN WRITTEN");
GetPlayer().SetVar("varGoEnd", true);
WriteToDebug("BUTTON BUTTON BUTTON BUTTON BUTTON BUTTON BUTTON BUTTON BUTTON ");

//run while and delay closing for x millsecs
while ((new Date()).getTime() < a) {}
}, false)

This code delays the closing of the browser for 2 secons (which works) but the GetPlayer().SetVar("varGoEnd", true); in the middles doesnt seem to run or causes an error that doesnt output to the debug window.

Debug Window.

159:Mon May 06 2019 19:59:38 GMT+0100 (British Summer Time) - strResult=true
160:Mon May 06 2019 19:59:38 GMT+0100 (British Summer Time) - Returning true

DURING THIS TIME USER IS ON SLIDE THAT CONTAINS CODE ABOVE THEN WINDOW IS CLOSED

161:Mon May 06 2019 19:59:41 GMT+0100 (British Summer Time) - WRITTEN WRITTEN WRITTEN WRITTEN WRITTEN WRITTEN
162:Mon May 06 2019 19:59:41 GMT+0100 (British Summer Time) - BUTTON BUTTON BUTTON BUTTON BUTTON BUTTON BUTTON BUTTON BUTTON

Hoping this further research migh spark and idea.

 

Zsolt Olah

I played with this a little a while back and ran into a couple of issues. The beforeunload event is not consistent between all browsers, mobile, etc. 

Also, even if you set the variable right before the window closes, SL won't save it. SL only sends suspend data when you move away from a slide. At least, that was my experience. So, I assume your varGoEnd variable was supposed to trigger an event in SL to move to the end.

However, at this point (beforeunload) the player object wasn't triggering things anymore. I didn't get further. I switched to trying to figure out how to send suspend data manually. This could done easily if you use xAPI but with SCORM I couldn't make it happen.  

Ben McKinstry

Zsolt thank you for your response! I believe I will be able to replace the beforeunload function with something in jquery which should become more browser friendly.

I have looked through the LMS API for Storyline and it seems there is a function SaveNow() that I can maybe call, it seems to update the LMS' 'datachunk'. Have you found that other functions would not run in the beforeunload, as I am  thinking of setting the variable then saving using the SaveNow function.

Might have a look into xAPI, only half way through getting my head around SCORM :)

This discussion is closed. You can start a new discussion or contact Articulate Support.