Link to home
Start Free TrialLog in
Avatar of robjohnston
robjohnston

asked on

Printing with HTML

Can you print from a button on a framed page? i.e. I have a page with a navbar and certian pages of my site folks might want to print out, but I don't want them to waste time printing out the navbar, just the relevant stuff as if it were a full witdh page.
Cheers, Rob.
Avatar of nettrom
nettrom

self.print() won't do?  if not, then how 'bout opening a child window and print its contents instead?
Avatar of robjohnston

ASKER

Didn't know about self.print() I'll give it a whirl and get back to you.
Avatar of knightEknight
The print() function will do this for NetScape.

 In IE you can include print.js -- see this site:
   http://msdn.microsoft.com/workshop/Author/script/DHTMLPRINT.asp

 and download this file:
    http://msdn.microsoft.com/workshop/Author/script/print.js 

 Once you include print.js, a print button can be done like this:

   <INPUT type='button' name='cmdPrint' value='Print' onClick='print()'>

 For more examples see:
    http://msdn.microsoft.com/workshop/Author/script/samp1.htm 
    http://msdn.microsoft.com/workshop/Author/script/samp2.htm 
    http://msdn.microsoft.com/workshop/Author/script/samp3.htm 

left out the "self":

 <INPUT type='button' name='cmdPrint' value='Print' onClick='self.print()'>
ASKER CERTIFIED SOLUTION
Avatar of tecbuilder
tecbuilder

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
tecbuilder, I don't see anything new come up in your reply.  what does it matter that print.js is Jscript, kEk correctly stated it was for IE as print() works in IE5/NN4.  I already mentioned opening the child window or using self.print() as kEk also stated...
Yes, the code above will work in NetScape regardless of print.js ...
The information I provide includes more specifics than generalities.  print.js may work fine in some of the later versions of Netscape 4.x, but are you sure it will work in -all- versions of Netscape.  Netscape 3.x doesn't interpret JScript and the last I heard, Netscape is still widely in all versions.  Also, what about those people who are not using IE4x or NS 4.x or later versions?

kEk did not mention that print.js will only work in IE 4.x as well.  As I interpretted his comment, it would work for all versions.  As for your comment, it seemed vague.  You said to open a child window and print it's contents.  What contents are you referring to?  It also seemed to me that you were unsure of your response.  My comments here are not to thrash you or kEk.

tecbuilder
tecbuilder, you miss the point...
print.js will have no effect on NetScape browsers because the first thing it does is check to see if window.print is a valid function, and if so, it does nothing else.  Therefore, window.print() will still work in NetScape as always.

print.js emmulates window.print() for IE -- which IS the point.  Since window.print() is not implemented in IE4 and below, print.js creates the function, so the code below will now work in IE4+ and NS3+ and perhaps earlier versions as well (I haven't tested)

<INPUT type='button' name='cmdPrint' value='Print' onClick='self.print()'>
I didn't miss the point, though I may not have stated my viewpoint well enough to make this clear.  Since print.js will have no effect on Netscape or IE 3.x browsers the necessary end result is not met (wanting to print just some part of a page), however what would happen is that the entire page would be printed.  Therefore the necessary end result has not been met.  Another way to say this, is that since print.js will only work for IE 4 and 5 and nothing else then the end result has not been accomplished.  Hence, the need for a solution that will work with at least the vast majority of browsers and their many versions.

tecbuilder
Ah.

If I read the question correctly, he wants to be able to print the contents of frame A from a button on frame B.  If so, then print() will work (with print.js in IE) by calling the print() method of frame A from the onClick of the button on frame B.  

If your reading of the question is correct -- that is, he only wants to print just part of a single page, then I agree, I don't see any way around that.
I too now see what you reading as well.  :-)