f



Download and Redirect... What am I missing ?

The script below allows me to link to a file and as the user clicks to
download, the 'File Download' windows appears as normal, and the user can
download...

The original page is then redirected to a new page..
This works, but it also opens a blank page..

How can this be chaged to stop the blank page from opening... ?

<script  type="text/javascript">
 function functionname(thefile){
    document.location.href="somepage.html"
    newwindow = window.open(thefile)
    newwindow.close
 }
</script>

<a href="#" onclick="functionname('filename.zip')">wqe</a> 

Thanks
0
James
8/22/2003 6:51:58 PM
comp.lang.javascript 38370 articles. 0 followers. javascript4 (1315) is leader. Post Follow

3 Replies
434 Views

Similar Articles

[PageSpeed] 53

James Kirk wrote:

> The script below allows me to link to a file and as the user clicks to
> download, the 'File Download' windows appears as normal, and the user can
> download...

No, it does nothing of the sort. What it does is navigates the current page
to "somepage.html".

> The original page is then redirected to a new page..
> This works, but it also opens a blank page..
>
> How can this be chaged to stop the blank page from opening... ?
>
> <script  type="text/javascript">
>  function functionname(thefile){
>     document.location.href="somepage.html"

The moment this line executes, "somepage.html" is loaded into the current
browser window and any lines after this point are discarded and not executed.
Also, it's "window.location.href". Most browsers do support
"document.location.href", but there's no guarantee it'll be supported in the
future.

>     newwindow = window.open(thefile)
>     newwindow.close

Neither of the above lines execute after you set window.location.href.

>  }
> </script>
>
> <a href="#" onclick="functionname('filename.zip')">wqe</a>
>
> Thanks

That should be:

<a href="#" onclick="functionname('filename.zip');return false;">wqe</a>

--
| Grant Wagner <gwagner@agricoreunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/author/dhtml/reference/dhtml_reference_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-developer/upgrade_2.html


0
Grant
8/22/2003 10:14:07 PM
On Fri, 22 Aug 2003 22:14:07 GMT, Grant Wagner <gwagner@agricoreunited.com>
wrote:

>James Kirk wrote:
>
>> The script below allows me to link to a file and as the user clicks to
>> download, the 'File Download' windows appears as normal, and the user can
>> download...
>
>No, it does nothing of the sort. What it does is navigates the current page
>to "somepage.html".
>
>> The original page is then redirected to a new page..
>> This works, but it also opens a blank page..
>>
>> How can this be chaged to stop the blank page from opening... ?
>>
>> <script  type="text/javascript">
>>  function functionname(thefile){
>>     document.location.href="somepage.html"
>
>The moment this line executes, "somepage.html" is loaded into the current
>browser window and any lines after this point are discarded and not executed.
>Also, it's "window.location.href". Most browsers do support
>"document.location.href", but there's no guarantee it'll be supported in the
>future.

Without the following line the download never starts !
>>     newwindow = window.open(thefile)
>>     newwindow.close
>
>Neither of the above lines execute after you set window.location.href.
>
>>  }
>> </script>
>>
>> <a href="#" onclick="functionname('filename.zip')">wqe</a>
>>
>> Thanks
>
>That should be:
>
><a href="#" onclick="functionname('filename.zip');return false;">wqe</a>
Changing to  this made no difference !

Any Ideas how I can start the download and redirect the current page to a
new one  ?

Thanks
0
James
8/23/2003 11:55:18 AM
James Kirk wrote:

> On Fri, 22 Aug 2003 22:14:07 GMT, Grant Wagner <gwagner@agricoreunited.com>
> wrote:
>
> >James Kirk wrote:
> >
> >> The script below allows me to link to a file and as the user clicks to
> >> download, the 'File Download' windows appears as normal, and the user can
> >> download...
> >
> >No, it does nothing of the sort. What it does is navigates the current page
> >to "somepage.html".
> >
> >> The original page is then redirected to a new page..
> >> This works, but it also opens a blank page..
> >>
> >> How can this be chaged to stop the blank page from opening... ?
> >>
> >> <script  type="text/javascript">
> >>  function functionname(thefile){
> >>     document.location.href="somepage.html"
> >
> >The moment this line executes, "somepage.html" is loaded into the current
> >browser window and any lines after this point are discarded and not executed.
> >Also, it's "window.location.href". Most browsers do support
> >"document.location.href", but there's no guarantee it'll be supported in the
> >future.
>
> Without the following line the download never starts !
> >>     newwindow = window.open(thefile)
> >>     newwindow.close
> >
> >Neither of the above lines execute after you set window.location.href.
> >
> >>  }
> >> </script>
> >>
> >> <a href="#" onclick="functionname('filename.zip')">wqe</a>
> >>
> >> Thanks
> >
> >That should be:
> >
> ><a href="#" onclick="functionname('filename.zip');return false;">wqe</a>
> Changing to  this made no difference !
>
> Any Ideas how I can start the download and redirect the current page to a
> new one  ?
>
> Thanks

function functionName(theFile){
    window.open(thefile, "_blank", "height=100,width=100");
    window.location.href = "somepage.html";
}

It'll leave you with an open window you can't close programmatically, and it may
not actually download the file, the browser will do whatever it wants with the
MIME type provided. For example, if it's a .DOC or .XLS file, the browser is IE
and MS Office is installed, it'll try and open the document in the 100 x 100
window.

The only way to force the browser to download regardless of it's default handling
of a particular MIME type is to use server-side technology to change the
Content-Type and Content-Disposition headers before the document is sent.

--
| Grant Wagner <gwagner@agricoreunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/author/dhtml/reference/dhtml_reference_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-developer/upgrade_2.html


0
Grant
8/25/2003 3:21:13 PM
Reply: