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. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/.
On Thu, Jun 11, 2009 at 9:23 PM, Ruby on Rails: Talk<dazzaroonie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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?
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: 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 11 June, 21:29, Xavier Noria <f...-xlncskNFVEJBDgjK7y7TUQ@public.gmane.org> wrote:> On Thu, Jun 11, 2009 at 9:23 PM, Ruby on Rails: > > Talk<dazzaroo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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<dazzaroonie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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 Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
This sounds excellent! Just need to work out how to do it. On Jun 11, 9:59 pm, Hassan Schroeder <hassan.schroe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Thu, Jun 11, 2009 at 1:49 PM, Ruby on Rails: > > Talk<dazzaroo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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 Schroeder ------------------------ hassan.schroe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
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 <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 --------------- div#for_screen_display { display:block; } div#for_print_display { display:none; } -------------- print.css -------------- 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
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. -- Posted via http://www.ruby-forum.com/.
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 <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 -------------- 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 On Jun 11, 5:49 pm, bill walton <bwalton...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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