Solved

Multiple file download

Posted on 1998-10-28
12
197 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
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

830 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