Download and Redirect... What am I missing ?

J

James Kirk

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
 
G

Grant Wagner

James said:
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 <[email protected]>

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

James Kirk

No, it does nothing of the sort. What it does is navigates the current page
to "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 !
Neither of the above lines execute after you set window.location.href.


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
 
G

Grant Wagner

James said:
Without the following line the download never starts !
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 <[email protected]>

* 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
 

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

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
44,998
Latest member
MarissaEub

Latest Threads

Top