Download a file

Post any questions you have about using the Verj.io Studio, including client and server-side programming with Javascript or FPL, and integration with databases, web services etc.

Moderators: Jon, Steve, Ian, Dave

Kaprice
Ebase User
Posts: 12
Joined: Sat Apr 04, 2015 3:43 pm
Contact:

Download a file

#1

Postby Kaprice » Mon Jul 27, 2015 5:22 pm

I've got code in eBase to create a CSV from the displayed table data.

Now I want to download it to the User.

Ideally, I'd like code that will pop up the User's Save As dialog (as if they'd clicked on a link).

But, if eBase can't do that, I'd like to create an invisible hyperlink with the URL to the CSV as the link and have eBase simulate clicking on that link.

Can either of the above be done?
0 x
Kap

Jon
Moderator
Moderator
Posts: 1342
Joined: Wed Sep 12, 2007 12:49 pm

#2

Postby Jon » Tue Jul 28, 2015 3:51 pm

The invisible hyperlink approach will work:

Set up a hyperlink control linked to the csv file - you can set the url as a variable if you want to so it's dynamic. Then set this hyperlink control as hidden by adding advanced style of display:none; This puts it on the page but makes it invisible to the user. Give the hyperlink an id using HTML element properties (say csv1).

Then invoke some client side Javascript to click the invisible link to download the file at the appropriate time e.g.

Code: Select all

<script> 
  var link = document.getElementById&#40;"csv1"&#41;;
  link.click&#40;&#41;;
</script>
You could include this Javascript in a variety of ways depending on what the trigger is to download the csv file:
o add it to an HTML control (initially hidden) and then just show this control at the appropriate time (you control this from the server)
o add it to a client-side ready event for a control (also controlled by the server)
o add it to some other client event (controlled by the client)
The browser's open/save dialog should appear.

There are probably smarter/tidier ways of doing this, but I tried it using an HTML control and it worked OK.
0 x

Kaprice
Ebase User
Posts: 12
Joined: Sat Apr 04, 2015 3:43 pm
Contact:

#3

Postby Kaprice » Tue Jul 28, 2015 5:03 pm

Thanks a bunch. Great approach.
0 x
Kap


Who is online

Users browsing this forum: No registered users and 24 guests