help_lucky Posted April 13, 2010 Share Posted April 13, 2010 Hi all, I want to print a page from another page. I have a master page with links to other page. When I click "print," it should print the another page. The function window.print() is printing only the active page. So on click print i am opening a new window. In the onload event of the target page i have used <body onload="window.focus();window.print();window.close ();"> Eventhough it's working, at the same time the window is also popping up behind the printer set up screen. when i click print or cancel the window gets closed automatically. i don't want the window to pop up. Do suggest me if there is any other alternative way.. Thanks for your help. Quote Link to comment https://forums.phpfreaks.com/topic/198349-print-another-page-without-window-popup/ Share on other sites More sharing options...
Psycho Posted April 13, 2010 Share Posted April 13, 2010 You can't print something that doesn't exist. Therefore, if the computer has not opened/loaded the content for the page, it can't print the page. However, there is one "hack" that I can think of by using some CSS properties. Using CSS you can set style properties for elements to be different based upon the "media" that the content is displayed in. For example, you can have page elements displayed differently in a browser than in a phone. One of the supported media types is the "print" media. This means you can have a page displayed ina browseer differently than it prints. This is what you could do. Create a DIV on the parent page which has a display=none default setting, but a display=inline for the print media type. Then for the rest of the content in the parent page, do the exact opposite. display=inline is the normal setting so you don't need to declare that, but give them a display=none for the print media. What this means is that when viewed in a browser the "print" div will be invisible, but when the page is printed, the contents of the div is the only thing that will be printed. Then it is just a matter of modifying your javascript to load the content you want to print into the DIV before initiating the print dialog for the parent page. Of course, this means the user will not be able to print the parent page as they see it. There are several posts on these forums regarding the media attributes for styles (a couple of which I have provided examples to) so you can search for those if you need more info. Quote Link to comment https://forums.phpfreaks.com/topic/198349-print-another-page-without-window-popup/#findComment-1040958 Share on other sites More sharing options...
help_lucky Posted April 15, 2010 Author Share Posted April 15, 2010 That's good idea. It's quite elaborative...Thanku for your time and for detailed response. I will try this way. Quote Link to comment https://forums.phpfreaks.com/topic/198349-print-another-page-without-window-popup/#findComment-1042308 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.