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 3 of 3
  1. #1
    Regular Coder mlse's Avatar
    Join Date
    Mar 2005
    Posts
    624
    Thanks
    20
    Thanked 19 Times in 18 Posts

    Printing a page without opening it ... is this possible?

    Hi,

    I've got a little bit of javascript to print a page from another page, as follows:

    In the javascript:
    Code:
    function printpage(url)
    {
      child = window.open(url, "", "height=1, width=1");  //Open the child in a tiny window.
      window.focus();  //Hide the child as soon as it is opened.
      child.print();  //Print the child.
      child.close();  //Immediately close the child.
    }
    In the HTML:
    Code:
    <input type="button" value="print another page" onclick="printpage('another.html');">
    This gives the illusion of printing a page (or you could print several pages by extending printpage) from a link in a different page without actually opening the other page (although we all know it does actually open the other page, it just hides it immediately and gets rid of it when printing is done).

    Is there any way of truly printing another page without opening it?

    TIA,
    Mike.
    Die Welt ist ein Irrenhaus und hier ist die Zentrale!

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    You will have to open it somewhere. Where it is opened, now, that's another story. You can hide it in an "invisible" iframe/frame, use xmlhttprequest to stream it to a new document and print that, or go another route.
    But the client has to see it sometime and all you get from plain old javascript is the window.print command.
    If this is for an intranet app, you may have a couple more options that are MSIE only, but in general, you'e stuck just hiding it somewhere.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #3
    Regular Coder mlse's Avatar
    Join Date
    Mar 2005
    Posts
    624
    Thanks
    20
    Thanked 19 Times in 18 Posts
    Thanks for that info, I might try fiddling with the invisible iframe solution - the current solution is satisfactory, but it does cause the child window to "flicker" into the user's view and then be immediately hidden. I like the invisible iframe solution - no "flicker"! Probably also immune to pop-up blockers, I should imagine ...
    Die Welt ist ein Irrenhaus und hier ist die Zentrale!


  •  

    Posting Permissions

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