Solved

Multiple file download

Posted on 1998-10-28
12
188 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 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
 
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Envision that you are chipping away at another e-business site with a team of pundit developers and designers. Everything seems, by all accounts, to be going easily.
The viewer will learn how to count occurrences of each item in an array.
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.

757 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now