0

I'm sure this has been asked before but can't seem to find it.

I've a (mostly) php page which has a simple button on it to print. Printing is done with a simple onClick="print.window()". Everything's fine in that it's calling the print.css correctly and what is being printed is what I expect. I'd like to have a method for asking the user if the document printed OK. If they say yes, I'll send them to a page that purges the php session and logs them out. If no, we'll either remain on or redisplay the page they tried to print.

I'm guessing this is going to be a javascript solution, and I have no problem using the jquery framework if that's easier.

Any suggestions would be greatly appreciated.

Thanks in advance,
-Ray

4
Contributors
8
Replies
10
Views
4 Years
Discussion Span
Last Post by rsleventhal
2

How about

<script type="text/javascript">
function printAndCheck() {
    print.window();
    var success = confirm("Did it print successfully?");
    if(success)
        window.location.href='logout.php';
    else
        window.location.reload();
}
</script>

and change your onclick to onclick="printAndCheck();"
Haven't tested but I think it should work.

0

yah EvolutionFallen seems right in addition just be sure the your logout function is int logout.php if youve got to follow his code =).

0

I'll try that this morning. Thanks to you both for the input. I'm pretty decent at PHP/MySQL, but not so much with javascript, though I'm learning. :)

I'll follow up here with success/fail, but it sure looks like it's the thing that I need.

Thanks!
-Ray

0

Thanks to EvolutionFallen and code739, it's working. One change, just for purposes of archives, is that the code should read window.print(), not print.window() (of course, I had that wrong in the title of my post, too!) Other than that, it does exactly what I'd hoped for.

Corrected code:

    function printAndCheck() {
    window.print();
    var success = confirm("Did the page print OK?");
    if(success)
    window.location.href='logout.php';
    else
    window.location.reload();
    }
    </script>

Thanks so much!

0

While the answer provided works as shown, I was encouraged to look at a jQuery/jQueryUI solution which would allow me to use prompts other than the default 'OK' and 'Cancel' which are part of 'confirm()'

That being said, I'm now stumped and hope someone here can point me in the right direction.

I'm linking to jQuery and jQueryUI in the head section of the document and have this in the body:

<script type="text/javascript">
  $(function confirmIt() {
    $( "#dialog-confirm" ).dialog({
      resizable: false,
      height:140,
      modal: true,
      buttons: {
        "Yes": function() {
          window.location.href='destroy';
        },
        "No": function() {
          window.print()
          }
      }
    });
  });
  </script>

Then, a bit lower down, I've got this in html:

<div id="custinfo">

    <input class="btn" type="button" onClick="confirmIt()" value="Print This Page" />

    <div id="dialog-confirm" title="Print Confirmation">
    <p><span class="ui-icon ui-icon-alert" style="float: left; margin: 0 7px 20px 0;"></span>Did the page print ok?</p>
    </div><!--dialog-confirm-->

</div><!--custinfo-->

What's happening when I get to the page is that the modal dialog is presented immediately. I'd like that to happen after the user clicks the 'print' button. The buttons within the modal dialog are doing what I'd like. It's just a matter of getting the 'print' button to call the window.print() function, then load the modal.

Any thoughts?

Thanks in adavance.
-Ray

Edited by bouncerfloridaalr: correction

0

Solved. Some syntactical difference with jQuery took some getting used to and while this is still a bit of a hack, it's working :)

Here was the solution:

    <script type="text/javascript">
      function confirmIt() {
      window.print()
        $( "#dialog-confirm" ).dialog({
          resizable: false,
          height:140,
          modal: true,
          buttons: {
            "Yes": function() {
              window.location.href='somepage.php';
            },
            "No": function() {
              window.print()
              }
          }
        });
      };
      </script>

And in the html:

<div id="dialog-confirm" style="display:none;" title="Print Confirmation">
    <p><span class="ui-icon ui-icon-alert" style="float: left; margin: 0 7px 20px 0;"></span>
    Did the page print ok?</p>
</div><!--dialog-confirm-->

One of the tricks was to set #dialog-confirm to display:none;, or the text within the <p> (after <span>) would display. This is now working, thanks to a LOT of help

Anyway...solved and solution provided for the archives.

-Ray

0

Thanks, EvolutionFallen. I was looking for a non-jQuery method as well, but time constraints got the better of me. I truly appreciate your help!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.