• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 288
  • Last Modified:

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.
0
robjohnston
Asked:
robjohnston
  • 5
  • 4
  • 2
  • +1
1 Solution
 
nettromCommented:
self.print() won't do?  if not, then how 'bout opening a child window and print its contents instead?
0
 
robjohnstonAuthor Commented:
Didn't know about self.print() I'll give it a whirl and get back to you.
0
 
knightEknightCommented:
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 

0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
knightEknightCommented:
left out the "self":

 <INPUT type='button' name='cmdPrint' value='Print' onClick='self.print()'>
0
 
tecbuilderCommented:
The only way that you can print exactly what you want is to open a new window or update a frame with what you want to have printed.  Browsers cannot print only certain parts of a window (except for framed windows) or certain parts of a frame.  It's all or nothing.  The information supplied above concerning a print.js script is JScript not JavaScript, meaning Netscape browsers will not work with this script.  Also, the print.js will only work with IE 4.x and later browsers.  The self.print function will only work with 4.x version browsers and it to will print the entire window or frame.
0
 
nettromCommented:
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...
0
 
knightEknightCommented:
Yes, the code above will work in NetScape regardless of print.js ...
0
 
tecbuilderCommented:
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
0
 
knightEknightCommented:
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()'>
0
 
tecbuilderCommented:
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
0
 
knightEknightCommented:
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.
0
 
tecbuilderCommented:
I too now see what you reading as well.  :-)
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 5
  • 4
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now