PDA

View Full Version : download a file on button click



TobyJustus
16 Apr 2012, 12:38 AM
In a formpanel i have a download button
{
xtype: 'button',
text: 'Download CSV',
style: 'margin:18px 0 0 10px',
handler: function () {
console.log('download data');
}

}

i want to download: export.csv when i click on this button. I tried to do it with
window.open('export.csv','download')

this is working in chrome, ff and ie9. But in ie8 it is not working unless you change a setting in the browser. Is there a better way to download a file using buttons?

friend
16 Apr 2012, 3:47 AM
I typically use an iframe to make a server-side request for a file:



// destroy any existing instance.
try {
Ext.destroy(Ext.get('downloadIframe'));
}
catch(e) {
// who you gonna call?
}

Ext.DomHelper.append(document.body, {
tag: 'iframe',
id:'downloadIframe',
frameBorder: 0,
width: 0,
height: 0,
css: 'display:none;visibility:hidden;height: 0px;',
src: 'file/download.action?targetFile=someFileIdentifier'
});