Jump to content

Archived

This topic is now archived and is closed to further replies.

darga333

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

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
You can use Javascript for that:
[code]window.close[/code]

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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
You'll want to use ajax then. That way you can interact with PHP and Javascript simultaneously.

Share this post


Link to post
Share on other sites
[!--quoteo(post=372216:date=May 8 2006, 02:46 AM:name=darga333)--][div class=\'quotetop\']QUOTE(darga333 @ May 8 2006, 02:46 AM) [snapback]372216[/snapback][/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?
[code]
// 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>
[/code]

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.