Copy link to clipboard
Copied
So, in my Captivate file, I want people to be able to download an XML file to their machine. If I create a hyperlink to "open a file", then when a user clicks on it, captivate attempts to open the xml file in a browser window instead of downloading it. I can't figure out how to use the download attribute for an href in captivate and I'm not sure if javascript to do this would execute properfly. Anybody know the best way to accomplish a force download of a file from a captivate presentation (Captivate 6)?
TIA.
Copy link to clipboard
Copied
You'll need to zip the file, then the user will be prompted to download and open.
Copy link to clipboard
Copied
I'm trying to avoid that. Have tried a couple of javascripts, but no luck so far. I am trying to make this as simple as possible for my users (yeah, I know, unzipping a file is easy, but if I can avoid it...).
Copy link to clipboard
Copied
If you want to really do this so that it is consistent for all browsers, you'll need to implement this at the server level. I did this with the Dynamic PDF Export Widget. Typically, a PDF will be displayed in the browser, but I added the ability to download it instead. It does require a PHP file (or some other server side script). In the PHP file, you'll want to set the response header for Content-Disposition to "attachment"... that's the key.
The elbow grease part has to do with managing how the browser handles the link. You'll want the Captivate hyperlink to open a new window so that the student does not navigate away from your course in the current window. But since you are opening a PHP file, you can inject javascript into the document of the new window/tab to close itself. The download will still continue eventhough the window/tab was programmatically closed. However, most modern browsers will automatically close the window/tab for you when downloading a file. If you want to see an example of a PHP file that implements this, go ahead and download the trial version of the Dynamic PDF Export widget. You'll see the create.php file in the zip package.
http://captivatedev.com/2012/07/25/adobe-captivate-6-x-widget-dynamic-pdf-export/
If you want to go simple as TLC Media Design suggested, just zip it and let your students unzip the xml file, or just rename the xml file with a .zip extension and tell them to rename the file back to .xml after downloading.
Copy link to clipboard
Copied
Thanks, Jim. I implemented something like this. What I could never understand through the couple hours I tried to get this to work the way I wanted to was why I couldn't simply plop in some simple javascript like below in an On Enter action and have it work:
window.open('http://www.yourdomain.com','windowname','
height='320,width=320,scrollbars,resizable');
I mean, Captivate says it implements javascript, that's javascript, so it should work, right? And I tried probably 15 different permutations of the same idea for hyperlinks, on enter actions and other areas using different javascript implementations, and none of them even budged. So I must REALLY be misunderstanding what Adobe says when they say it allows you to implement javascript, because something that simple should be a no-brainer. What am I missing?
Copy link to clipboard
Copied
The JavaScript Captivate uses is all done in the user's browser (client side). But the server is the one serving up the xml file and it must tell the browser how to display the requested file. Should the browser display the XML in the window, or download it? The server sends a message to the user's browser to instruct how it should display the XML file. It does this through the Content-Disposition header. if the Content-Disposition reads "inline", then the browser knows that it should show the file in the window. If the server sends the Content-Disposition header as "attachement", the browser is instructed to receive the downloaded file.
Unfortunately, JavaScript cannot fix this because it can't run on the server or instruct the server what to do. JavaScript can only run within the context of the end user's browser. (I can hear the node.js zealots screaming right now). The window.open() code listed above will only open a new browser window. It will not instruct the browser how to display the xml file. There are some JS hacks, but they don't work consistently across all browsers and even the different versions of the same browser behave differently. So the only reliable way to approach this issue is to use a server-side script.
Copy link to clipboard
Copied
Sure. But I couldn't even get Captivate to open a 300 x 300 window for an html page I threw together with a link and instructions on how to download the file. So, window.open() should at LEAST have opened http://yourdomain.com/filename.html in a new window, but it wouldn't even do that, just nothing. That's what was frustrating me, I couldn't even implement a workaround of a workaround.
Copy link to clipboard
Copied
I see. The code that was posted had a few single quotes in the wrong place. I've modified it like so:
window.open('http://www.yourdomain.com','windowname',height='320',width='320',true,true);
Does that work for you?