Solved

Multiple file download

Posted on 1998-10-28
12
200 Views
Last Modified: 2013-12-25
How can I supply a link which will download multiple files? E.g. I have two GIFs and want to download them both in one go from the same link/button.
0
Comment
Question by:BOINGED
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
  • 3
12 Comments
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 100 total points
ID: 1855961
Gifs will not download (they get displayed in the browser) but if you want to load them into cache, the following should do it:
<SCRIPT>
function loadImages() {
   if (!document.images) return; // IE3 does not support this
   Image1 = new Image(); Image1.src = 'image1.gif';
   Image2 = new Image(); Image2.src = 'image2.gif';
}
</SCRIPT>
<A HREF="javascript:loadImages()">Cache two images</A>


0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 1855962
Alternatively try this:
<HTML>
<HEAD>
<SCRIPT>
function loadImages() {
   var Text = '<IMG SRC="image1.gif"><IMG SRC="image2.gif">'
   top.imageframe.document.open();
   top.imageframe.document.write(Text);
   top.imageframe.document.close();
}
</SCRIPT>
</HEAD>
<FRAMESET ROWS="10%,*">
<FRAME NAME="linkframe" SRC="test.htm">
<FRAME NAME="imageframe" SRC="javascript:' '">
</FRAMESET>
</HTML>

and in test.htm have
<A HREF="javascript:top.loadImages()">Load two images</A>

Hope this helps,

Michel
0
 

Author Comment

by:BOINGED
ID: 1855963
Thanks for your prompt reply, however I may have been unclear with my question, what I want to do is to enable a user to download two files, not neccessarily GIFs, to their hard disk with the click of a single button. Like when you press shift & click on a html link it will save/download the html file, but I need it for, say, multiple html files.
0
Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 1855964
I understand, however you cannot force a download of files that the browser thinks it can display so gif, jpg, txt and so on can only be downloaded with a browser specific action like shift-click or right-click+save-as.
Zipped files and executables are different and you have some more possibilities:
1. one click loads two files into separate frames, that should trigger two save-as prompts
2. one click executes a server based function that zips the two files and returns them

1:
<HTML>
<HEAD>
<SCRIPT>
function loadTwo() {
   top.hidden1.location='file1.zip';
   top.hidden2.location='file2.zip';
}
</SCRIPT>
</HEAD>
<FRAMESET ROWS="100%,*,*>
<FRAME NAME="contents" SRC="normal.htm">
<FRAME NAME="hidden1" SRC="javascript:' '">
<FRAME NAME="hidden2" SRC="javascript:' '">
</FRAMESET>
</HTML>

and in normal.htm have
<A HREF="javascript:loadTwo()">Download two files</A> please answer OK when prompted to save...

Michel
0
 
LVL 28

Expert Comment

by:sybe
ID: 1855965
michel,
that's a clever approach. I wonder if you really need a frameset for this.

What about just a plain page:
====
<html>
<head>
<script>
function DownloadFiles() {
  document.location = 'zipfile1.zip';
  document.location = 'zipfile2.zip';
}
</script>
</head>
<body onload="DownloadFiles()">
</body>
</html>
=====

since the zips are not displayed, the original HTM page remains in the window. I've gotta try this out !
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 1855966
Sybe: In my experience it must be in two different frames or one frame and a timeout, but the timeout is hard to calculate:
function DownloadFiles() {
   top.otherframe.document.location = 'zipfile1.zip';
   setTimeout("top.otherframe.document.location = 'zipfile2.zip'",100000);
}

If the onLoad could be used, the second download could be initiated onLoad, but I believe this even is triggered almost immediately if it is a non-displayable file

Let me know what you find...

Michel
0
 

Author Comment

by:BOINGED
ID: 1855967
I tried your solution Michel and after I fixed the bugs :) got it working in IE4 but not Communicator 4.5 - is that just due to Netscape's DOM being different to Microsofts?
sybe your solution doesn't work - only the second file is ever downloaded.
Thanks for your assistance, will grade soon if there are no more comments.
0
 
LVL 28

Expert Comment

by:sybe
ID: 1855968
I found some weird code that works in one document. It does not work in IE3. But it works in NS3, as long as the files that should be downloaded are are present on the server.

<html>
<head>
<script>

strEmpty = '';
arrFiles = new Array('zipfile1.zip', 'zipfile2.zip', 'zipfile3.zip', 'zipfile4.zip');
myLinks = new Array();

for (i=0;i<arrFiles.length;i++){
  myLinks[i] = strEmpty.link(arrFiles[i]);
  document.write(myLinks[i]);
}
for (i=0;i<arrFiles.length;i++){
  if (document.links) {
    document.location.href = document.links[i];
  }
}
</script>
</head>
<body bgcolor="#FFFFFF"">


</body>
</html>


0
 
LVL 28

Expert Comment

by:sybe
ID: 1855969
There are some weird things to the code:

1. it creates invisible links
2. it redirects the document to the url of a link without an event.

Hmm, somehow I don't think that Javascript was made for this :). But it's fun trying.

0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 1855970
I cannot see the DOM make any difference unless you use document.all or something...
Would you care to paste the code that works in IE but not Netscape?

Michel

0
 

Author Comment

by:BOINGED
ID: 1855971
This is weird. this code actually works in Netscape but not IE.

test.htm contains:

<HTML>
<HEAD>
<SCRIPT>
function loadTwo()
{
top.hidden1.location='file1.zip';
top.hidden2.location='file2.zip';
}
</SCRIPT>
</HEAD>
<FRAMESET ROWS="100%,*,*">
<FRAME NAME="contents" SRC="normal.htm">
<FRAME NAME="hidden1" SRC="javascript:' '">
<FRAME NAME="hidden2" SRC="javascript:' '">
</FRAMESET>
</HTML>

and normal.htm contains:

<A HREF="javascript:top.loadTwo()">Download two files</A> please answer OK when prompted to save...

I'll try the sybe's weird code but I think I'll go for a self-extracting archive, damn now I've got to register pkzip :)
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 1855972
Very strange... Could you please try the following before discarding IE:
top.hidden1.location='http://www.myserver.com/file1.zip';
top.hidden2.location='http://www.myserver.com/file2.zip';

changing the http://www.myserver.com/ for the location of the files...
Also change the 100%,*,* to
33%,33%,*
so you can see any webserver messages

If that does not work, please try

top.hidden1.location='http://www.myserver.com/file1.zip';
setTimeout("top.hidden2.location='http://www.myserver.com/file2.zip'",3000);

just for fun...

the zip files should come from the server, not from harddisk...

Michel

0

Featured Post

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Because your company can’t afford for you to make SEO mistakes, you’ll want to ensure you’re taking the right steps each and every time you post a new piece of content. This list of optimization do’s and don’ts can help you become an SEO wizard.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question