Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Multiple file download

Posted on 1998-10-28
12
Medium Priority
?
203 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
  • 6
  • 3
  • 3
12 Comments
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 400 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

963 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