Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing Window 1

Status
Not open for further replies.

Mugs321

Programmer
Jan 31, 2007
49
CA
Hey all,
Here's the deal... I've got a page with some clickable icons which are used to 'View' a test and 'Print' a test. The 'View' icon opens a new window and the test is displayed.

What I want to do is allow the 'View' page to be printed, when the 'Print' icon is clicked, without displaying the 'View' page to the user.

My first thought was to just move it off the screen:
Code:
self.moveTo(-1000, 0);
this.print();
setTimeout("this.close()", 1000);  //Allow time for print dialog to display

I also thought about setting the width/height to zero (which apparently can't be done).

I just wanna know if there's a more elegant way of doing this.

Thx.
 
I do have a media="print" stylesheet on the page to be printed and the print displays as it should. However, I want to initiate the print from another page without displaying the page I want printed. As far as I know, this is beyond the scope of CSS.
 
I personally don't see the point.

If necessary, do what google maps does - open the window and initiate the print automatically.

If you want to print a separate page, it needs to be opened somewhere. You could also try a hidden iframe.



*cLFlaVA
----------------------------
[tt]"quote goes here"[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
You could also use AJAX to load the page into a hidden div on the page invoking the the print. And then, apply the print stylesheet to the page invoking the print to hide the entire contents of the page and only show the new page that has been loaded into the div via AJAX.

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson
 
hehe..

I gave the iFrame option a shot and I'm running into some problems. The iframe works, the page loads, everything's hunky-dory...

Until, that is, I try to print.

I started by trying to initiate the print from the page that's loaded in the iframe. That printed the parent page.

I tried setting focus, the printing using getElementById:
Code:
function printAttempt(url1){
   objFrame = document.getElementById('printFrame');
   objFrame.src = url1;
   setTimeout("objFrame.focus();", 1000);	//Give page time to load
   objFrame.print();
}
That gave me an error on the print() method.

Then I tried using the frames[] collection:
Code:
function printAttempt(url1){
   frames[0].src = url1;
   setTimeout("frames[0].focus();", 1000);	//Give page time to load
   frames[0].print();
}
This worked but still printed the parent page.

Is it even possible to print ONLY the iframe page (as if that page were loaded into it's own window)??
 
my sample worked perfectly:

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]

<html>
<head>
<title>Untitled</title>
</head>

<body>

<h1>stupid header</h1>
<button onclick="top.frames['blah'].focus(); top.frames['blah'].print();">Print the iframe</button><br />
<iframe name="blah" id="blah" src="other.html"></iframe>

</body>
</html>



*cLFlaVA
----------------------------
[tt]"quote goes here"[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top