Close window after binary download

C

chon

I have an ASP page that is sent a file location as a parameter. It opens
this file, loads the ADODB.Stream object and does a binary write to the page
forcing the download dialog to appear. This all works fine. If the user
selects "Open" or "Cancel", the window closes, which is the desired behavior.
If they select "Save", the location dialog shows up, they save the file and
the window remains open. I've tried a number of things to get the window to
close automagically, or at least to get a "Close window" button or link to
show up, but nothing has worked. Is this possible, or will my users always
have to close the window manually?
 
P

Patrice

I don't see this behavior. The download doesn't open a new window. How do
you call the download page ?

I would suggest to use just an anchor tag wiht no target. The browser will
get the new content and as this is not an HTML content :
- the current page remains intact
- it just opens the donwload dialog without any "new window"

Patrice
 
C

chon

Hi, Patrice,

The new window is being launched via Javascript:
window.open("Download.asp?Filelocation=<file path>","download",strFeatures).
We're doing it this way because we don't want to overwrite the current window
(which will happen if the browser recognizes the file type and displays it).
We also want to give the user the option to open it or download it rather
than letting the browser decide.

Thanks,

Chon
 
P

Patrice

Sorry, I thought you were really already "forcing" the download dialog.

http://support.microsoft.com/default.aspx?id=260519 allows to force the
download dialog even for know mime types.
This way you have always the same behavior and you don't have to open this
new window...

Is it applicable or do you actually WANT to have the current behavior for
know mime types ?

Patrice

--
 
C

chon

Hi, Patrice,

Thanks for the pointer to the article. Perhaps I'm being dense, but I don't
see how it's possible to send the content-disposition header without
submitting the page so that either some ASP code executes within the page, or
a new page is launched that will handle the Response.AddHeader. If I submit
the page to itself and execute Response.AddHeader to change
content-disposition to "attachment", the HTML content of the page will no
longer display so I might as well launch a different page, no?

The reason for opening a new window is to preserve the contents of the page
from which the download is being requested. The download.asp page that we're
currently using is forcing the download dialog by using the
Response.AddHeader and that works correctly, however, there's no way to
display an HTML button to close the page once the download is complete if the
user chooses "Save" instead of "Open" or "Cancel". At least there's no way
that I've been able to find.

Thanks,

Chon
 
P

Patrice

The key point is that the browser decides what to do not before but *after*
getting the new content. Based on the header, the browser sees that it
should raise a download dialog and that there is then no need to recycle the
window (at least this is what we see using IE). Its content is then left
unchanged and as a result you don't need this new window to protect the
content.

The KB article allows to always raise this dialog so that it will take
always the same decision (ie raise the dialog instead of displaying
automatically the new content).

You may want still to give this a try with the browsers you are supporting
but I'm quite confident the behavior should be the same.

If you keep the new window option, the only thing I can think of would be to
trigger the download using a frame (possibly a IFRAME or even an IMG tag) so
that you can have some script that closes the window either automatically
once the document is entirely completed or by using asking for user input as
a last resort.

Hope it helps.

Patrice

--
 
C

chon

Hi, Patrice,

Okay, I'm going to have to play with that a while and see if it will work
the way we're constructing our pages. Thanks very much for your time.

Chon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top