Forum Discussion

ronald-hicks's avatar
ronald-hicks
Community Member
3 hours ago

Free snippet: let learners download their notes as a .txt file (no libraries, 2 minutes)

Here's a tiny freebie: a Download button that saves a learner's text-entry response as a .txt file. No libraries, no setup beyond two variables — paste it into an Execute JavaScript trigger on the button:

// FREEBIE: Download button — saves a learner's text-entry response as a .txt file.
// Setup (30 seconds): create two text variables — MyNotes (default blank)
// and DL_Status (default blank). Put a text-entry field on the slide and
// rename its auto-created variable to MyNotes.
// Then paste this into: Execute JavaScript, When the user clicks your button.
// Put this trigger ABOVE any Jump trigger on the same button — a jump that
// fires first skips the code below it.
(function () {
  var player = GetPlayer();
  var text = player.GetVar("MyNotes");
  if (!text || !text.trim()) { player.SetVar("DL_Status", "empty"); return; }
  var blob = new Blob([text], { type: "text/plain" });
  var link = document.createElement("a");
  link.href = URL.createObjectURL(blob);
  link.download = "my-notes.txt";
  document.body.appendChild(link);
  link.click();
  setTimeout(function () { URL.revokeObjectURL(link.href); link.remove(); }, 500);
  player.SetVar("DL_Status", "downloaded");
})();

 

No RepliesBe the first to reply