0

I have a page with the following:

<script>
    window.setInterval(function () {
        var cookie = $.cookie('download');
            if (cookie !== null) {
                console.log(cookie);
            }
    }, 500); 
</script>

It is checking a cookie called download and its value of 0 (previously set) is being displayed in the console.

From this page I can click a button which launches a php pdf generating file and just before the pdf is output (to download the pdf) have:

<?php 
    ... pdf created ...
    setcookie("download", 1);
    output pdf;
?>

suposedly to mark set the cookie as 1 to indicate the download is complete. However this change is not reflected in the console and the cookie remains with the value 0.

Is what I am trying to do possible? And if so what am I doing wrong?

This method is proposed with this question: Is there any event/way we can know when a file has finished downloading?

Community
  • 1
  • 1
RGriffiths
  • 5,722
  • 18
  • 72
  • 120
  • And mark down by all means but please say why. – RGriffiths Sep 01 '16 at 12:09
  • 1
    Cookies are sent in response header. Even tho I'm not sure what are you trying to accomplish, you can't expect that cookie will simply appear like that. – Mladen Ilić Sep 01 '16 at 12:11
  • I am trying to acheive a way of knowing when a pdf file generated by php has downloaded. It is asked a great deal and I have included the link of a method. So I need to find out how to read the header in the output - is that what you are saying? – RGriffiths Sep 01 '16 at 12:14
  • The cookie is there - it is displaying 0 - what I want to do is to change it to 1 when the pdf has completed downloading. – RGriffiths Sep 01 '16 at 12:15

0 Answers0