-
16 Apr 2012 12:38 AM #1
Answered: download a file on button click
Answered: download a file on button click
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 withwindow.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?
-
Best Answer Posted by friend
I typically use an iframe to make a server-side request for a file:
Code:// 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' });
-
16 Apr 2012 3:47 AM #2
I typically use an iframe to make a server-side request for a file:
Code:// 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' });


Reply With Quote