faqts : Computers : Programming : Languages : JavaScript : Document

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

48 of 63 people (76%) answered Yes
Recently 6 of 10 people (60%) answered Yes

Entry

How can I offer the user to download and save several (non html) files?
How can I offer the user to download and save several (non html) files?

Apr 16th, 2000 07:20
Martin Honnen,


With IE4+ you can insert an IFRAME with STYLE="display: none;" to 
achieve this, NN6 can dynamically insert IFRAMEs but refuses to load 
content with display set to none so you have to use STYLE="visibility: 
hidden;" which might affect page layout. NN4 can only open new windows 
with the files to download:

<HTML>
<HEAD>
<SCRIPT>
function downloadFiles () {
  for (var f = 0; f < arguments.length; f++) {
    if (document.all) {
      var html = '';
      html += '<IFRAME';
      html += ' NAME="buffer' + f + '"';
      html += ' STYLE="display: none;"';
      html += ' SRC="' + arguments[f] + '"></\IFRAME>';
      document.body.insertAdjacentHTML('beforeEnd', html);
    }
    else if (document.layers) {
      open(arguments[f])
    }
    else if (document.getElementById) {
      var iframe = document.createElement('IFRAME');
      iframe.setAttribute('id', 'buffer' + f);
      iframe.setAttribute('name', 'buffer' + f);
      iframe.setAttribute('src', arguments[f]);
      iframe.setAttribute('style', 'visibility: hidden;');
      document.body.appendChild(iframe);
    }    
  }
}
</SCRIPT>
</HEAD>
<BODY>
<A HREF="javascript: downloadFiles (
    'http://www.w3.org/TR/html4/html40.zip',
    'http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/DOM.zip'
  );"
>
download html and dom specs
</A>
<BR>
</BODY>
</HTML>