1. #1
    Sencha User
    Join Date
    Apr 2011
    Location
    Netherlands
    Posts
    51
    Vote Rating
    0
    TobyJustus is on a distinguished road

      0  

    Default 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 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?

  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'
    });

  3. #2
    Sencha - Community Support Team friend's Avatar
    Join Date
    Apr 2011
    Posts
    895
    Answers
    106
    Vote Rating
    27
    friend has a spectacular aura about friend has a spectacular aura about

      1  

    Default


    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'
    });

Thread Participants: 1

Tags for this Thread