Digital Workshop

Welcome to the Digital Workshop Message Boards
It is currently December 22nd, 2024, 1:32 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: HTML5 write/download to text file
PostPosted: October 14th, 2016, 3:06 pm 
Offline
Godlike
Godlike

Joined: November 11th, 2004, 1:18 pm
Posts: 1213
Location: New York
Opus: Opus Pro 9.75
OS: Windows 10 Pro 64 bit
System: Core i7, 16G RAM, Nvidia 640GT (desktop), plus Windows 10 and Android tablets
Here's an interesting tutorial to save data, download as a text file in HTML5 using JavaScript: http://www.tutsandtips.com/javascript/how-to-download-a-text-file-with-javascript/
From the above link:
Code:
<!doctype html>
<html>
<head>
  <title>JavaScript Text File Download Demo</title>
</head>
<body>
  <a href="" id="download">Download</a>
  <script>
  var fileName = 'myfile.txt';
  var fileContent = 'Page content...';
  var myFile = new Blob([fileContent], {type: 'text/plain'});

  window.URL = window.URL || window.webkitURL;
  document.getElementById('download').setAttribute('href', window.URL.createObjectURL(myFile));
  document.getElementById('download').setAttribute('download', fileName);
  </script>
</body>
</html>


Additional similar scripting from JSFiddle (including working demo):
http://jsfiddle.net/k56eezxp/ and http://jsfiddle.net/UselessCode/qm5AG/.

I threw the first script above into an Opus HTML5 test pub (can download IMP, etc. here: https://eLearningprojects.com/tester7.zip).

Can be used by adding it in Advanced publishing tab.

But not familiar enough with translating/using it in Opus, for example, (1) to figure out how to call the named function from an Opus button, (2) or to populate the text file with data from variables inside the Opus pub (like test scores). (Do these get referred to as DW Pub variables? Or prefaced by window.variable, etc.? Use Opus script object or Opus JavaScript object?)

Essentially to bring control of these JavaScript functions inside Opus HTML5 so be able to change/customize it's use in the Opus pub, call the functions from an Opus button, maybe link to and call the JS functions from a linked external JS file.

Goal is to give the user, who takes a few tests, gets scores, to be able to encrypt/save/download these scores in a txt file onto their computer.

How to translate into a more usable script to use from inside Opus?

_________________
Stephen


For this message Stephen has been thanked by : mackavi


Top
 Profile  
 
 Post subject: Re: HTML5 write/download to text file
PostPosted: October 17th, 2016, 11:35 am 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
Hi Stephen,

It's a potential idea but at the moment the 'download' attribute has limited browser support - so it won't work for a lot of users.

In terms of taking it forward, you can add it directly to a button using a JS action and:

Code:
var fileName = 'myfile.txt';
var fileContent = 'my name is Stephen...';
var myFile = new Blob([fileContent], {type: 'text/plain'});

window.URL = window.URL || window.webkitURL;


var link = document.createElement('a');
document.body.appendChild(link);
link.setAttribute("id","download")
link.style.display = "none";

var dl = document.getElementById('download')
dl.setAttribute('href', window.URL.createObjectURL(myFile));
dl.setAttribute('download', fileName);
dl.click();
dl.parentNode.removeChild(dl);


</mack>

_________________
When you have explored all avenues of possibilities, what ever remains, how ever improbable, must be the answer.

Interactive Solutions for Business & Education
Learn Anywhere. Learn Anytime.

www.interaktiv.co.uk
+44 (0) 1395 548057


Top
 Profile Visit website  
 
 Post subject: Re: HTML5 write/download to text file
PostPosted: October 17th, 2016, 2:13 pm 
Offline
Godlike
Godlike

Joined: November 11th, 2004, 1:18 pm
Posts: 1213
Location: New York
Opus: Opus Pro 9.75
OS: Windows 10 Pro 64 bit
System: Core i7, 16G RAM, Nvidia 640GT (desktop), plus Windows 10 and Android tablets
Thank you, Mack.

I tried using a variable to populate the text file. Appears that reference to a variable, already being used in the pub, needs to be prefaced with _DWPub. (plus the variable).

Again, thank you.

_________________
Stephen


For this message Stephen has been thanked by : mackavi


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 51 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group