Client side Save as dialog

Trenutno provjereno radi u Chrome i Firefox preglednicima.

1. u js-u kreiraj Blob objekt koji sadrži podatke koje šalješ klijentu

var data = ['Vrijeme;ChargeCurrent;LoadCurrent;Voltage2013.01.178:34:28;0.24;0.28;13.152013.01.17 09:50:48;0.36;0.22;13.452013.01.17 11:15:54;0.39;0.33;13.69'];
var blob = new Blob([data], {type : 'text/csv'});

2. Kreiraj data uri do Blob objekta

var url = URL.createObjectURL(blob);

3. Kreiraj ili modificiraj anchor

var anchor = document.getElementById('a');
anchor.href = url;
anchor.download = '1.csv'; // Naziv i ekstenzija datoteke

 

Ovako izgleda finalni element

<a id="a" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA
AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
9TXL0Y4OHwAAAABJRU5ErkJggg==" download="red_dot.png">Download red dot</a>

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.