help with the following code (open a download dialogue and then redirect to a new page)

K

kevinm3574

So, I'm doing the following in a php script so that I can fire a
download dialogue AND redirect the page (after clicking submit in a
form). I'm doing it this way because of the problem with headers and
such and server-side vs client-side issues:

$dir = "somedir";
$file = "somefile";

print("
<script language=\"JavaScript\">
<!--
my_window =
window.open('get.php?dir=packages$dir&file=$file','Downloading','width=1,height=1,resize=no');
window.location.href = '$redirpage';
setTimeout('window.close()', 5000);
//-->
</script>");

Everything works here EXCEPT for the closing of the d**n empty window
that is opened. My get.php fires to open a new dialogue to download
the file I want, the page I was on gets redirected to $redirpage, but
the empty window doesn't close. If I DON'T use setTimeout and just do
the following:

print("
<script language=\"JavaScript\">
<!--
my_window =
window.open('get.php?dir=packages$dir&file=$file','Downloading','width=1,height=1,resize=no');
window.location.href = '$redirpage';
my_window.close();
//-->
</script>");

then the window closes but too fast for the get.php to pop up the
download dialogue (hence my need to delay the close of the window a
bit). I've tried using setTimeout('my_window.close()', 5000); but the
empty window never closes. This is driving me nuts as it appears it
should be fairly straight forward. Any assistance is greatly
appreciated. (BTW, I'm fairly novice at this so any better ideas on how
to do what I'm trying to do is also greatly appreciated).

Thanks.

Kevin
 

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

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top