Forum Discussion
SamClark
7 years agoCommunity Member
Exit SL via JavaScript
I'd like to write a script that alerts the learner and exits the course after learner acknowledgment.
I could do a window.close() but some LMS encapsulate the course so using the built-in SL EXIT ...
OwenHolt
7 years agoSuper Hero
Are you talking about a typical web page alert box?
In SL, set a variable called Exit_Course with a default value of "False".
Execute the following JS based on your triggering action.
let player = GetPlayer();
function myFunction() {
if (confirm("You are about to exit the course!")) {
player.SetVar("Exit_Course",true);
} else {
console.log("User Cancelled Exit!");
}
};
myFunction();
In SL, add an action to EXIT COURSE when the VARIABLE Exit_Course changes IF Exit_Course is equal to True.
So basically, the JS controls the variable and the variable controls the exit function in SL.
Related Content
- 5 months ago