Wrox Programmer Forums
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 1st, 2004, 02:41 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default print()

I have a page that when the user clicks a button, it should open a popup and print it.

However, what I am doing is opening a blank page and writing on it, then telling it to print from the opener.

Nothing happens when I use this code:
Code:
//onclick fires this function:
function print_page()
{
 //this part works fine...
 var newpage = window.open("","newpage");
 //this part works fine...
 newpage.document.write("a bunch of data");
 //this part does nothing!
 newpage.window.print();

 //I have also tried:
 newpage.print();
 newpage.document.print();
 //and several other things...
}
Perhaps this is some sort of security issue? I get no errors, just nothing...

Thanks

Snib

__________________
-Snib - http://www.snibworks.com
Where will you be in 100 years?
 
Old January 2nd, 2004, 11:57 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

You need to close document before printing:
Code:
newpage.document.write("a bunch of data...");
newpage.document.close();
newpage.print();
--

Joe
 
Old January 2nd, 2004, 12:05 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Thank you Joe, works perfectly.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Textbox problem print preview vs. print jenisageek Access 5 May 2nd, 2008 12:54 PM
print the hidden page without the print dialog box kayzem Classic ASP Basics 0 April 21st, 2005 11:31 PM
Print and print preview file on the website withou appleLover General .NET 0 February 19th, 2005 02:24 AM
Macro to print to different print objects mikericc Access 1 April 21st, 2004 10:57 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.