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
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
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?
[…]
Most browsers these days understand CSS @media directives, so use a
print stylesheet to turn off display on all other elements.
Marnen Laibow-Koser
http://www.marnen.org
[email protected]
On Thu, Jun 11, 2009 at 9:23 PM, Ruby on Rails:
Talk[email protected] wrote:
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?
I am not sure I understand what you mean, but just in case I am lucky,
perhaps you are looking for factoring out the DIV into a partial?
On Thu, Jun 11, 2009 at 1:49 PM, Ruby on Rails:
Talk[email protected] wrote:
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.
If it’s always the same, and you never want to print everything else
on the page, a simple print style sheet would do.
–
Hassan S. ------------------------ [email protected]
Hi
No 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:
But I wonder if there is something easier?
Cheers
Darren
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
Basically…
In the 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.
Now create the two stylesheets.
div#for_screen_display {
display:block;
}
div#for_screen_display {
display:none;
}
div#for_print_display {
display:print;
}
When the browser loads the page, it notes that you’ve specified
different stylesheets for different media and takes care of the rest.
HTH,
Bill
This sounds excellent!
Just need to work out how to do it.
On Jun 11, 9:59 pm, Hassan S. [email protected]
Bill that was really good information and detailed - many thanks! I was
actually looking for something like this about 3 days ago but put it on
the backburner.
I’m bookmarking the thread for later use.
Thanks.
Hi,
On Fri, 2009-06-12 at 00:42 +0200, Älphä Blüë wrote:
Bill that was really good information and detailed - many thanks! I was
actually looking for something like this about 3 days ago but put it on
the backburner.I’m bookmarking the thread for later use.
Thanks.
You’re welcome. Glad you found it helpful.
Best regards,
Bill
or
div#for_screen_display {
display:none;
}
this way of someone is using a device that doesn’t support css they
don’t see screen and print content. and less to download
on a side note there’s no reason to make a div display: block; they
already are.
Cheers,
John
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs