Issues: Using Javascript to block access to a client's course

I have a course that will be used by multiple clients on an annual licence basis. I want to be able to "turn off" a course (i.e. block access) if a client does not renew their licence.

The best theoretical solution I could come up with is based on this blog post. My idea is this:

  1. When a client's licence expires I upload a blank HTML file to my Amazon S3 account (bear with me!)
  2. When the timeline starts on the first slide javascript (inspired by the blog post) is triggered.
  3. The javascript checks to see if there is a web page with my client's name.
  4. If there is then a trigger jumps the user to a slide "Sorry, your licence has expired". If there is not then the course acts as normal and is fully accessible.

Unfortunately I cannot get the code (based on the blog post) to work. I have also tried a few other similar solutions.

Does anyone have any ideas what I am doing wrong? Or can you suggest an alternative solution that would allow me to block access? I am aware of SCORM Cloud Dispatch but I'm afraid my budget is zero...

Here's my code. Many thanks!

// Establish link between SL and JS
var player = GetPlayer();

// Bring SL variables into JS
var licenceExpired = player.GetVar("licenceExpired");

// Added JS creates a function for checking if a page exists
function doesFileExist(urlToFile) {
var xhr = new XMLHttpRequest();
xhr.open('HEAD', urlToFile, false);
xhr.send();

if (xhr.status == "404") {
return false;
} else {
return true;
}
}

// Calls function on URL that I feed it
var result = doesFileExist("https://www.example.com/clientname.html");

// Assigns a boolean value to the licenceExpired variable
if (result == true) {
licenceExpired = true;
} else {
licenceExpired = false;
}


// Send variable back to SL
player.SetVar("licenceExpired", licenceExpired);
Be the first to reply