Current location: Hot Scripts Forums » General Web Coding » JavaScript » Help with javascript print code?


Help with javascript print code?

Reply
  #21 (permalink)  
Old 05-30-07, 11:56 PM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
Don't say I never gave you nothing. LOL

Thumbnail page:
HTML Code:
<html>
<style>
.btn
{
 border:none;
 background:none;
 text-decoration:underline;
 color:#0000ff;
 }
</style>
<body>

<!-- image 1 -->
<span style="text-align:center;width:100px;">
<img src="http://www.animalmakers.com/Catalog/images/airedale_5515-01.jpg" width="75px" height="75px">
<br>
<button class="btn" onclick="window.open('preview.php?pic=1','','width=400px,height=400px,top=175px,left=300px')">Print picture</button>
</span>


<!-- image 2 -->
<span style="text-align:center;width:100px;">
<img src="http://www.animalmakers.com/Catalog/images/airedale_5515-01.jpg" width="75px" height="75px">
<br>
<button class="btn" onclick="window.open('preview.php?pic=2','','width=400px,height=400px,top=175px,left=300px')">Print picture</button>
</span>


<!-- image 3 -->
<span style="text-align:center;width:100px;">
<img src="http://www.animalmakers.com/Catalog/images/airedale_5515-01.jpg" width="75px" height="75px">
<br>
<button class="btn" onclick="window.open('preview.php?pic=3','','width=400px,height=400px,top=175px,left=300px')">Print picture</button>
</span>


<!-- image 4 -->
<span style="text-align:center;width:100px;">
<img src="http://www.animalmakers.com/Catalog/images/airedale_5515-01.jpg" width="75px" height="75px">
<br>
<button class="btn" onclick="window.open('preview.php?pic=4','','width=400px,height=400px,top=175px,left=300px')">Print picture</button>
</span>


<!-- image 5 -->
<span style="text-align:center;width:100px;">
<img src="http://www.animalmakers.com/Catalog/images/airedale_5515-01.jpg" width="75px" height="75px">
<br>
<button class="btn" onclick="window.open('preview.php?pic=5','','width=400px,height=400px,top=175px,left=300px')">Print picture</button>
</span>

</body>
</html>
preview.php
PHP Code:

<html>

<body>
<?php
if(isset($_GET["pic"])){$pic_to_print $_GET["pic"];}
switch(
$pic_to_print)
{
 case 
1:
        echo 
"<div style='text-align:center;'>
              <img src='http://www.animalmakers.com/Catalog/images/airedale_5515-01.jpg'>
              <br>
              <p><button onclick=\"this.style.display='none';print();document.getElementById('btn1').style.visibility='visible';\">Print</button></p>
              <p><button id='btn1' style='visibility:hidden;' onclick='window.close();'>Close window</button></p>
              </div>"
;
        break;
 case 
2:
        echo 
"<div style='text-align:center;'>
              <img src='Put address of next image here'>
              <br>
              <p><button onclick=\"this.style.display='none';print();document.getElementById('btn2').style.visibility='visible';\">Print</button></p>
              <p><button id='btn2' style='visibility:hidden;' onclick='window.close();'>Close window</button></p>
              </div>"
;
        break;
 case 
3:
        echo 
"<div style='text-align:center;'>
              <img src='Put address of next image here'>
              <br>
              <p><button onclick=\"this.style.display='none';print();document.getElementById('btn3').style.visibility='visible';\">Print</button></p>
              <p><button id='btn3' style='visibility:hidden;' onclick='window.close();'>Close window</button></p>
              </div>"
;
        break;
 case 
4:
        echo 
"<div style='text-align:center;'>
              <img src='Put address of next image here'>
              <br>
              <p><button onclick=\"this.style.display='none';print();document.getElementById('btn4').style.visibility='visible';\">Print</button></p>
              <p><button id='btn4' style='visibility:hidden;' onclick='window.close();'>Close window</button></p>
              </div>"
;
        break;
 case 
5:
        echo 
"<div style='text-align:center;'>
              <img src='Put address of next image here'>
              <br>
              <p><button onclick=\"this.style.display='none';print();document.getElementById('btn5').style.visibility='visible';\">Print</button></p>
              <p><button id='btn5' style='visibility:hidden;' onclick='window.close();'>Close window</button></p>
              </div>"
;
        break;
 }
?>
</body>
</html>
Is this what you mean?

Or if you want the print and close window buttons both visible at first and the close window button visible after you print, then change preview.php to this:

preview.php
PHP Code:

<html>

<body>
<?php
if(isset($_GET["pic"])){$pic_to_print $_GET["pic"];}
switch(
$pic_to_print)
{
 case 
1:
        echo 
"<div style='text-align:center;'>
              <img src='http://www.animalmakers.com/Catalog/images/airedale_5515-01.jpg'>
              <br>
              <p><button onclick=\"this.style.display='none';document.getElementById('btn1').style.display='none';print();document.getElementById('btn1').style.display='block';\">Print</button></p>
              <p><button id='btn1' onclick='window.close();'>Close window</button></p>
              </div>"
;
        break;
 case 
2:
        echo 
"<div style='text-align:center;'>
              <img src='Put address of next image here'>
              <br>
              <p><button onclick=\"this.style.display='none';document.getElementById('btn2').style.display='none';print();document.getElementById('btn2').style.display='block';\">Print</button></p>
              <p><button id='btn2' onclick='window.close();'>Close window</button></p>
              </div>"
;
        break;
 case 
3:
        echo 
"<div style='text-align:center;'>
              <img src='Put address of next image here'>
              <br>
              <p><button onclick=\"this.style.display='none';document.getElementById('btn3').style.display='none';print();document.getElementById('btn3').style.display='block';\">Print</button></p>
              <p><button id='btn3' onclick='window.close();'>Close window</button></p>
              </div>"
;
        break;
 case 
4:
        echo 
"<div style='text-align:center;'>
              <img src='Put address of next image here'>
              <br>
              <p><button onclick=\"this.style.display='none';document.getElementById('btn4').style.display='none';print();document.getElementById('btn4').style.display='block';\">Print</button></p>
              <p><button id='btn4' onclick='window.close();'>Close window</button></p>
              </div>"
;
        break;
 case 
5:
        echo 
"<div style='text-align:center;'>
              <img src='Put address of next image here'>
              <br>
              <p><button onclick=\"this.style.display='none';document.getElementById('btn5').display='none';print();document.getElementById('btn5').style.display='block';\">Print</button></p>
              <p><button id='btn5' onclick='window.close();'>Close window</button></p>
              </div>"
;
        break;
 }
?>
</body>
</html>
I am sure there must be numerous ways to lay these pages out, but this is the general method used. And there may be better ways to do this, but this is simple and effective. Have fun.
__________________
Jerry Broughton
Reply With Quote
  #22 (permalink)  
Old 05-31-07, 12:06 PM
pcinfoman pcinfoman is offline
Coding Addict
 
Join Date: Jan 2006
Posts: 264
Thanks: 0
Thanked 0 Times in 0 Posts
I used the bottom code for my "preview.php" file because I want the "Print" and "Close Window" buttons there at the same time. It is working. However, when I choose "Print", it prints and the "Print" button goes away.

How can I make it so the buttons stay there all the time?
Reply With Quote
  #23 (permalink)  
Old 05-31-07, 01:53 PM
pcinfoman pcinfoman is offline
Coding Addict
 
Join Date: Jan 2006
Posts: 264
Thanks: 0
Thanked 0 Times in 0 Posts
I figured out the answer to my last question. I have it installed and it is working flawlessly on the site.

THANK YOU SO MUCH FOR YOUR HELP.

In a perfect world, I would not need all of this. The customer would just push the "print this image" button under the thumbnail and it would just print the image. Too bad we do not live in a perfect world.

Is there anyway to automate this tho? Is it possible for the customer to push the "print this image" button and have it automatically bring up the image in a new window, bring up the print dialog, and when the print job is done, close the popup window?

Is that wishful thinking?
Reply With Quote
  #24 (permalink)  
Old 05-31-07, 02:40 PM
Vicious's Avatar
Vicious Vicious is offline
Community VIP
 
Join Date: Jan 2007
Location: Belgium
Posts: 584
Thanks: 0
Thanked 0 Times in 0 Posts
yes, that is wishful thinking: the browser has no control/knowledge about anything else besides the browser. Printing is not done by the browser itself, but via drivers. You simply can't steer that process via regular scripting.
__________________
Jack Bauer makes Chuck Norris cry
Reply With Quote
  #25 (permalink)  
Old 06-01-07, 07:27 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
Like this:
PHP Code:

<html>
<body>
<?php
if(isset($_GET["pic"])){
switch(
$_GET["pic"])
{
 case 
1:
        echo 
"<div style='text-align:center;'>
              <img src='http://www.animalmakers.com/Catalog/images/airedale_5515-01.jpg'>
              <br>
              <p><button onclick=\"this.style.display='none';document.getElementById('btn1').style.display='none';print();document.getElementById('btn1').style.display='block';this.style.display='block';\">Print</button></p>
              <p><button id='btn1' onclick='window.close();'>Close window</button></p>
              </div>"
;
        break;
 case 
2:
        echo 
"<div style='text-align:center;'>
              <img src='Put address of next image here'>
              <br>
              <p><button onclick=\"this.style.display='none';document.getElementById('btn2').style.display='none';print();document.getElementById('btn2').style.display='block';this.style.display='block';\">Print</button></p>
              <p><button id='btn2' onclick='window.close();'>Close window</button></p>
              </div>"
;
        break;
 case 
3:
        echo 
"<div style='text-align:center;'>
              <img src='Put address of next image here'>
              <br>
              <p><button onclick=\"this.style.display='none';document.getElementById('btn3').style.display='none';print();document.getElementById('btn3').style.display='block';this.style.display='block';\">Print</button></p>
              <p><button id='btn3' onclick='window.close();'>Close window</button></p>
              </div>"
;
        break;
 case 
4:
        echo 
"<div style='text-align:center;'>
              <img src='Put address of next image here'>
              <br>
              <p><button onclick=\"this.style.display='none';document.getElementById('btn4').style.display='none';print();document.getElementById('btn4').style.display='block';this.style.display='block';\">Print</button></p>
              <p><button id='btn4' onclick='window.close();'>Close window</button></p>
              </div>"
;
        break;
 case 
5:
        echo 
"<div style='text-align:center;'>
              <img src='Put address of next image here'>
              <br>
              <p><button onclick=\"this.style.display='none';document.getElementById('btn5').display='none';print();document.getElementById('btn5').style.display='block';this.style.display='block';\">Print</button></p>
              <p><button id='btn5' onclick='window.close();'>Close window</button></p>
              </div>"
;
        break;
 }
}
?>
</body>
</html>
</html>
This javascript is getting quite long, and I would probably make a function to do this. But this will work.
__________________
Jerry Broughton

Last edited by job0107; 06-01-07 at 07:30 AM.
Reply With Quote
  #26 (permalink)  
Old 06-01-07, 05:36 PM
pcinfoman pcinfoman is offline
Coding Addict
 
Join Date: Jan 2006
Posts: 264
Thanks: 0
Thanked 0 Times in 0 Posts
Well, I don't care about the length of the script right now. It is working perfectly and it is for a specific use. If I end up using it throughout my site, then I might look for a streamlined approach.

Thank you for your help.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Classified Ads skipper23 Perl 3 11-22-05 02:22 AM
CGI problem - Script only allows a small number of digits in my customers site url??? Ireland Perl 6 10-09-05 07:09 PM
Mysql Search Output Question doveroh PHP 0 02-15-05 07:39 PM
formmail problem gscraper Perl 12 08-27-04 03:06 AM
Upload Script Problem!!! seanknighton Perl 0 03-21-04 09:54 PM


All times are GMT -5. The time now is 11:26 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.