SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Close popup after downloading file

    Hello there,

    I have a page which has a button that says Progress Report In PDF. When i click on the button, it shows a pop up window with an textarea to enter some comments before creating the report in PDF. The comment entered would be saved in the database and also it would be printed in the PDF. So when i click on Generate PDF button on the pop up window after entering some comment, it creates the PDF report file and lets me download the created file. But when the file is ready to download or downloading completes the pop up window must be closed.

    I have this script to download the file:
    PHP Code:
    $pdf_data '';
    $filename "CP_Project_$project_id.pdf";
    header('Content-type: application/pdf');
    header('Content-Disposition: attachment; filename="' $filename '"');
    echo 
    $pdf_data;
    exit(); 
    I also try to redirect the page without having the pop up, this also cannot be done at all.

    So any help would be thankful.

    With Regards
    Raju Gautam
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Popups are controlled with JS.

    When the page appears with the download in it, wait for a reasonable time, then make the window close itself.

    use a JS Timer to :
    window.close();

    You can try and catch focus on the opening page, and cause the popup to close but its all a bit of a nightmare. I find silently closing popups is best, it'll depend on how critical the content of the pop up is to your app. e.g. Can the pdf be regenerated IF the user has lost focus on that pop up?

    PHP Code:
    <script type="text/javascript">
    <!--

    var msg;
    function killWin(x){
    msg = '<?php echo $c->g[title]; ?> - calendar window left open.  Close it?';
    window.setTimeout("if(confirm(msg)){ self.close();}else{killWin(20000);}",x);
    }

    //-->
    </script>
    </head>
    <body onload="initCalendar();killWin(20000);">
    Here's another way with a confirm box, then killWin

  3. #3
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanx Cups, I have already done setting the timer but without giving an alert. Close the window after certain seconds. I am not sure how must this method is good. when i submit the comment form on the pop up then i did like this:
    Code:
    	function frmReportValidate(fm){
    		if(fm.comments.value == "" || fm.comments.length == 0){
    			alert('Please type at least some comments.');
    			fm.comments.focus();
    			return false;
    		}
    		fm.action = '../ip6/progress_report_export.php';
    		fm.method = 'post';
    		fm.submit();
    		TimerRaju();
    	}
    	var secs = 1;
    	function TimerRaju(){
    		if (secs == 10){
    			self.close();
    		}
    		secs = secs + 1;
    		timerID = self.setTimeout("TimerRaju()", 1000);
    	}
    <form name="frmreportcomment" onSubmit="return frmReportValidate(this);">
    form elements...
    </form>
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  4. #4
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    I think I did the Confirm because some users become very confused by pop ups, not realising they go behind the window. The Confirm takes the screen over to remind them they need to close it.

    I thought that in your case the user clicks a button to download the pdf file, and I imagined (perhaps incorrectly), that the window must stay onscreen until the download finishes, meaning you had to guess how long that might take and then let the window close itself after a reasonable time.

    You seem to be saying that the window closes when the form is submitted, does this not knobble the download? - if not then I am failing to understand your question.

    If the download button is on a popup window, and once clicked the download happens regardless of whether the popup is open, then you just kill the window don't you?

    Otherwise my suggestion for a Timer and Confirm.

  5. #5
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes Cups, I am not saying that you could not understand my problem. You are absolutely right on the solution though from your side.

    I just unknowingly want to know if there is any way without using such javascript timer to see. And exactly like you say, there is a problem on how much time the download is going to take. For the time being as you can see i have waited for only 10 seconds which is might not be enough to download the file in the slow connection computers. So i have to think some other ways if there are.

    And appreciating your suggestion, i still would like to request you to provide if some other ways for this other than that i have used here.
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  6. #6
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    The only thing that springs to mind is to generate the js timer timeout period from the size of the download. I mean are your pdfs going to vary in size a lot?

    You might have to do some homework to figure out a "worst case" dial up timing something like 3 minutes per megabyte or similar.

    Another way might be to use the JS parent.opener relationship to go back and write a division in the DOM of the opening page with the pdf link in it, and let users download it from there.
    (warning: now I am talking about something I have never done, I use parent.opener to write back to form elements, but not to the DOM)


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •