Jump to content


Photo

How do you close a window immediately after someone clicks a "Print" button.


  • Please log in to reply
6 replies to this topic

#1 darga333

darga333
  • Members
  • PipPipPip
  • Advanced Member
  • 53 posts

Posted 08 May 2006 - 06:46 AM

How do you make the window close immediately after you click "Print" but still allow it to print the page that the "Print" button was on and also allow it to update the database with print = 1.

The order of operations would be:

1. Click Print

2. Run SQL Query
$sql = "UPDATE print SET print=1 WHERE user_id='$user_id'";
$result = mysql_query($sql);

3. Print Dialog Pop Up

4. Immediately close window

Does anyone know how to do this?

#2 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 08 May 2006 - 08:27 AM

You won't be doing that with just PHP, I can tell you that much. You'll need to use a client side language to do the closing of the window - JavaScript?

#3 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 08 May 2006 - 08:28 AM

You can use Javascript for that:
window.close

You won't be able to do this in PHP, only javascript.

#4 darga333

darga333
  • Members
  • PipPipPip
  • Advanced Member
  • 53 posts

Posted 08 May 2006 - 03:41 PM

would I close the window as soon as the print dialog pops up?

the part about this whole thing that i dont understand is that the print button has to be attached to an onClick

but in that onclick it is ganna be javascript.. how can i go from javascript to php to update the database?

bcause javascript is client side and php is server side.. so when they click print do i have to have it submit to the same page first, then inside of the code... if it has been submitted, then do the php first.. and then call the javascript to popup the print window and close the window in that order?

#5 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 08 May 2006 - 04:18 PM

You'll want to use ajax then. That way you can interact with PHP and Javascript simultaneously.

#6 lead2gold

lead2gold
  • Members
  • PipPipPip
  • Advanced Member
  • 164 posts
  • LocationOttawa, On

Posted 08 May 2006 - 04:42 PM

[!--quoteo(post=372216:date=May 8 2006, 02:46 AM:name=darga333)--][div class=\'quotetop\']QUOTE(darga333 @ May 8 2006, 02:46 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
How do you make the window close immediately after you click "Print" but still allow it to print the page that the "Print" button was on and also allow it to update the database with print = 1.

The order of operations would be:

1. Click Print

2. Run SQL Query
$sql = "UPDATE print SET print=1 WHERE user_id='$user_id'";
$result = mysql_query($sql);

3. Print Dialog Pop Up

4. Immediately close window

Does anyone know how to do this?
[/quote]

the window you pop up.... could it not have a form on it?
// assume this is print.php
$go_print = (isset($_POST['go_print']))?true:false;

<?php

if($go_print){
   // execute sql statement here
}

?>
<html><head><title>print and update db</title></head>
<body <? ($go_print)?"onload=\"window.close();\"":""; ?>>
<form name="print" action="print.php">
<b>Press Print:</b>
<input type="hidden" name="go_print" value="">
<input type="submit" name="print">
</form>
</body>
</html>

I mean.. correct my syntactical errors i made above (as it's not tested). But the logic is basically there...

#7 darga333

darga333
  • Members
  • PipPipPip
  • Advanced Member
  • 53 posts

Posted 08 May 2006 - 08:03 PM

yeah how it works is

a "Print" link will be displayed.. that print link will make the print.php page pop up

it will pass a variable print = 1

then i will run the SQL statement and update the database

then it will pop up the print dialog box

and then it will immediately close the window..

The question:

Once the print dialog box pops up does it automatically know to print what was on the page that the Print button was on (print.php) even if i close the window before the person clicks to actually print the document?? or do you have to have the window open, and then the person prints it and only after it is printed, then you can close the window? I need to make sure that the person is actually going to print what was on the print.php page.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users