Download and Redirect... What am I missing ?

Discussion in 'Javascript' started by James Kirk, Aug 22, 2003.

  1. James Kirk

    James Kirk Guest

    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
    James Kirk, Aug 22, 2003
    #1
    1. Advertising

  2. James Kirk

    Grant Wagner Guest

    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 <>

    * 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
    Grant Wagner, Aug 22, 2003
    #2
    1. Advertising

  3. James Kirk

    James Kirk Guest

    On Fri, 22 Aug 2003 22:14:07 GMT, Grant Wagner <>
    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
    James Kirk, Aug 23, 2003
    #3
  4. James Kirk

    Grant Wagner Guest

    James Kirk wrote:

    > On Fri, 22 Aug 2003 22:14:07 GMT, Grant Wagner <>
    > 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 <>

    * 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
    Grant Wagner, Aug 25, 2003
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Carole MacDonald

    Form to request download, and redirect

    Carole MacDonald, Sep 13, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    349
    Bruno Piovan
    Sep 13, 2004
  2. Gary Herron
    Replies:
    2
    Views:
    663
    Bruno Desthuilliers
    Jul 4, 2006
  3. Les Caudle
    Replies:
    0
    Views:
    496
    Les Caudle
    Oct 31, 2006
  4. Sal
    Replies:
    1
    Views:
    409
  5. kevinm3574
    Replies:
    1
    Views:
    83
    kevinm3574
    Aug 31, 2005
Loading...

Share This Page