By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,433 Members | 776 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,433 IT Pros & Developers. It's quick & easy.

Download and Redirect... What am I missing ?

P: n/a
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
Jul 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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 <gw*****@agricoreunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_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-deve...upgrade_2.html
Jul 20 '05 #2

P: n/a
On Fri, 22 Aug 2003 22:14:07 GMT, Grant Wagner <gw*****@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
Jul 20 '05 #3

P: n/a
James Kirk wrote:
On Fri, 22 Aug 2003 22:14:07 GMT, Grant Wagner <gw*****@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 <gw*****@agricoreunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_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-deve...upgrade_2.html
Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.