Click to See Complete Forum and Search --> : using window.location to download attachment causes error


Guyon
04-23-2003, 02:09 AM
I am trying to add an option in our site where the user can click on a button to download an ASP generated file.

The code looks a bit like this...

<a href="javascript:void(0);"
onclick="o = MyGetObj('results'); if ( o ) window.location = 'my.asp?ext=GetCSV&ids=' + o.getIDs()"
>Get it here</a>

The first time the user clicks on this link, everything works, which is great.

But after that, if they use the page again, it crashes the browser. I suspect that the bit where I'm changing window.location is causing the browser to throw away its old state.

Is there a better way to do this using just Javascript and HTML?

DrDaMour
04-23-2003, 02:53 AM
do a window.open instead, if it's just a file teh window will close automatically

Guyon
04-23-2003, 09:19 AM
Thanks DrDaMour & Dave,

the server side of things is working fine - I'm setting all the necessary HTTP headers 'n stuff.

The problem is in the client. After setting window.location I have a feeling that the browers throws away all its DOM state in anticipation of the next page, but the next page is not a page, it's an attachment. So the browser is left in a crazy state causing problems.

The idea from DrDaMour to use window.open solves the crashing problem, but doesn't always automatically close the new window which is another problem.

I've settled on an approach where the page offering the download opens a new window for the download and then after a while attempts to close it.

Unless anyone can suggest a better way.

DrDaMour
04-23-2003, 09:24 AM
hidden iframe that you target for download.

Guyon
04-28-2003, 04:12 AM
Thanks again to DrDaMour & Dave,

I have gone with the hidden iframe model and that is working just fine without the internet explorer crashes.

cheers guys