Jump to content

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


darga333

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.