468,554 Members | 1,841 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,554 developers. It's quick & easy.

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

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

Aug 30 '05 #1
2 1625
kevinm3574 schrieb:
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>");


in this variant, you would close the main-window, not the popup. You want to
close my_window, not this window. But the Problem is an other: Your're leaving
the page, that has the information about the popup-window and setTimeout (AFAIK)
don't survives a location-change. So something like this should work:

my_window.setTimeout('self.close()', 5000);

This way, you're applying the Timeout to the popup-Window.

Greetings,

Martin
Aug 30 '05 #2
Martin,

Thanks!!! That works great. I appreciate your responding.

Kevin

Aug 31 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by pargat singh | last post: by
2 posts views Thread by Bobby | last post: by
7 posts views Thread by Joe | last post: by
3 posts views Thread by Chuck Renner | last post: by
5 posts views Thread by dm3281 | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.