Force download and close window

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
amir
Forum Contributor
Posts: 287
Joined: Sat Oct 07, 2006 4:28 pm

Force download and close window

Post by amir »

Here is the code snipet i use to force download. After the save download pops up IE closes the window but Firefox does not. How can i make firefox close the window?

Code: Select all

header('Content-Type: text/comma-separated-values');
if (strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE')){
     header('Content-Disposition: inline; filename="'.$rpt->report_type.'.csv"');
     header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
     header('Pragma: public');
} else {
     header('Content-Disposition: attachment; filename="'.$rpt->report_type.'.csv"');
     header('Pragma: no-cache');
}//end if
TIA!
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Force download and close window

Post by Chris Corbyn »

amir wrote:Here is the code snipet i use to force download. After the save download pops up IE closes the window but Firefox does not. How can i make firefox close the window?

Code: Select all

header('Content-Type: text/comma-separated-values');
if (strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE')){
     header('Content-Disposition: inline; filename="'.$rpt->report_type.'.csv"');
     header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
     header('Pragma: public');
} else {
     header('Content-Disposition: attachment; filename="'.$rpt->report_type.'.csv"');
     header('Pragma: no-cache');
}//end if
TIA!
Does it need to be in a popup?

Either way, perhaps:

Code: Select all

var w;

function killWindow()
{
    try {
        w.close()
    } catch (e) {}
}

w = window.open( .... );
w.onload = killWindow;
Post Reply