Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New to the CF scene
    Join Date
    Apr 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    onclick print command prints blank page

    Hi I am trying to get my coupons to open a new window then print using the following code, but am having a small issue, the window opens fine, the print dialog comes up, but the print function does not print the image, just a blank page. what am I missing?

    Code:
     <img src="http://randys-pizza.com/wp-content/uploads/2013/04/freeknotsoda.png" width="461" height="282" onclick="newWindow = window.open('http://randys-pizza.com/wp-content/uploads/2013/04/freeknotsoda.png'); newWindow.print();" />
    Last edited by VIPStephan; 04-02-2013 at 11:59 PM. Reason: fixed code BB tag

  • #2
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,478
    Thanks
    6
    Thanked 981 Times in 954 Posts
    Quote Originally Posted by tmcglynn View Post
    what am I missing?
    Perhaps a printer setting that disables printing of images? People can do that, you know?

  • #3
    New to the CF scene
    Join Date
    Apr 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I am testing the code on my own laptop and if I ignore the pop up print dialogue and choose to manually go to file>print it will print correctly from the new window correctly. I do not have the images set to not print on my printer so it would appear that is not the issue. But I had not thought of that thanks for the reply

  • #4
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,465
    Thanks
    0
    Thanked 634 Times in 624 Posts
    It might also be a timing issue since the image will take some time to load in the new window that you are printing as soon as it has opened. See if the following makes any difference (by adding a one second delay beween opening the new window and printing it.

    Code:
     <img src="http://randys-pizza.com/wp-content/uploads/2013/04/freeknotsoda.png" width="461" height="282" onclick="newWindow = window.open('http://randys-pizza.com/wp-content/uploads/2013/04/freeknotsoda.png'); setTimeout(newWindow.print,1000);" />
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #5
    New to the CF scene
    Join Date
    Apr 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by felgall View Post
    It might also be a timing issue since the image will take some time to load in the new window that you are printing as soon as it has opened. See if the following makes any difference (by adding a one second delay beween opening the new window and printing it.

    Code:
     <img src="http://randys-pizza.com/wp-content/uploads/2013/04/freeknotsoda.png" width="461" height="282" onclick="newWindow = window.open('http://randys-pizza.com/wp-content/uploads/2013/04/freeknotsoda.png'); setTimeout(newWindow.print,1000);" />
    Thank you for the reply, I think I am getting closer with your suggestion, now the page does not print blank anymore! so that is a plus, unfortunately by changing my coding how you suggested it now wants to print the entire page instead of just the coupon itself. suggestion?

  • #6
    New to the CF scene
    Join Date
    Apr 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    OK, after doing some more fumbling around I came across http://jsbin.com if I just place the code as it is the way you suggest it works flawlessly, printing just the coupon and not the whole page.

    I then proceeded to copy and paste the entire page source into jsbin.com to see what would happen, the issue comes again.

    If I remove the setTimeout parameter and go back to my original coding the page would print blank in jsbin.com so somehow the Timeout function relays back to the website instead of remembering to print the new window that we created?

  • #7
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,465
    Thanks
    0
    Thanked 634 Times in 624 Posts
    So you need the timeout so as to give time for the image to load before you print it.

    If that isn't working with the rest of your page then something else must be interfering with it.

    Perhaps if you change the onclick to:

    Code:
    onclick="(function() {var newWindow = window.open('http://randys-pizza.com/wp-content/uploads/2013/04/freeknotsoda.png'); setTimeout(newWindow.print,1000);})();"
    That might prevent the interferance.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #8
    New to the CF scene
    Join Date
    Apr 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    something must still be interfering with even changing the code that way, it must just not like me . Just messing around with it again this morning I have found that if I cancel the print dialogue that we launch and then choose to File>print from the new window it will print the coupon itself and not the entire page? Now I am really perplexed.

  • #9
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    it's a timing issue, it almost always is in this scenario. I would try increasing the time on the timeout before anythign else.

  • #10
    New to the CF scene
    Join Date
    Apr 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by DanInMa View Post
    it's a timing issue, it almost always is in this scenario. I would try increasing the time on the timeout before anythign else.
    Thanks Dan,
    I will play around with your suggestion.

    if anyone would like to see how the page interacts I have made the page live with the current code printing the whole page instead of the image, maybe that will help troubleshoot?

    http://randys-pizza.com/coupon-club/

  • #11
    New to the CF scene
    Join Date
    Apr 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by DanInMa View Post
    it's a timing issue, it almost always is in this scenario. I would try increasing the time on the timeout before anythign else.
    Tired increasing the time up to 30000 and still no luck :-\. I went ahead and made the page live so it will just print the entire page for now. I'm still searching for the fix, but it is beginning to look like it may just not want to work the way I want it to. Which is frustrating, thanks for your suggestion. any more ideas would be very welcomed


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •