Printing the contents of a DIV

Hi

Is there any way to be able to get a function (or something?!) to print the contents of a DIV without loading the div into it's own window etc?

I've googled like crazy but seem to be asking the impossible. Any ideas?

Thanks

Darren

On Thu, Jun 11, 2009 at 9:23 PM, Ruby on Rails:

Hi

No :frowning: Sorry.

I'I have a number of DIV's on a page. One of which contains a calendar or events. Rather than have to reload a page with just the calendar on it (to allow for printing), it would seem easier to find a way to click a button and only the div containing the calendar will print.

I've got close to understanding it with the following link:

http://lloydi.com/blog/2006/03/21/how-to-print-selective-sections-of-a-web-page-using-css-and-dom-scripting-2/

But I wonder if there is something easier?

Cheers

Darren

On Thu, Jun 11, 2009 at 1:49 PM, Ruby on Rails:

This sounds excellent!

Just need to work out how to do it.

Hi Darren,

On Thu, 2009-06-11 at 12:23 -0700, Ruby on Rails: Talk wrote:

Hi

Is there any way to be able to get a function (or something?!) to print the contents of a DIV without loading the div into it's own window etc?

I've googled like crazy but seem to be asking the impossible. Any ideas?

Google "CSS print stylesheet example". Hassan and Marnen are correct. The links you'll get from the search above will get you to a point where you understand what they said :wink:

Basically...

In the <head> section of your layout (typically application.rhtml), you specify the stylesheets you want to use and, optionally, which 'media' they're to be used for. The choices are screen, print, or all. Here's an example from one of mine.

<%= stylesheet_link_tag 'application', :media => 'screen' %> <%= stylesheet_link_tag 'print', :media => 'print' %>

These helper methods result in the application.css file being used to style pages sent to the screen, and the print.css file being used to style pages sent to the printer.

Put the two lines above in the head section of your layout. Create an .rhtml view with the following.

<body>   <div id="for_screen_display">     I'm your screen buddy!   </div>   <div id="for_print_display">     I'm your print buddy!   </div> </body>

Now create the two stylesheets.

application.css

Hi,

or <body>   <div id="for_screen_display">     this is stuff I don't want to print.   </div>   <div id="for_screen_and_print_display">     this is content for screen and print.   </div> </body>

print.css