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

How could I hide some elements on screen but not on printer?

I need to hide some DIV's on a page (style="display:none") but I'd like to print them when I call the script :

window.print();

If I use style="display:none" all of those DIV's are not printed...

Is It possible???

JpmSoft


0
JpmSoft
Asked:
JpmSoft
  • 3
  • 3
  • 2
  • +2
3 Solutions
 
Rahulkumar007Commented:
For Div using the style directely use css file and assighn class for style.

You can add a different stylesheet for different media.

So while printing that particular style sheet will be applied.

<LINK media="print" href="../Includes/PrintSummary.css" type="text/css" rel="stylesheet">


0
 
ashleydbCommented:
Have a stylesheet for screen as shown:

.noPrint {
      display: block;
}
.Print {
      display: block;
}


Have a stylesheet for print as shown:

.noPrint {
      display:none;
}
.Print {
      display: block;
}


Put them in your html (or whatever) files in the <HEAD> as shown:

<LINK href="Print.css" media="print" type="text/css" rel="stylesheet">
<LINK href="Screen.css" media="screen" type="text/css" rel="stylesheet">


Then you can apply the style Print or noPrint to areas that you want to be displayed when you print or don't.

<table class="noPrint">


The opposite needs to be applied if you want things to print, but not show on screen.


And finally, remember you can apply more than one style to an object so you can set up any styles you want for a header table for example, then have it not print.

<table class="headertable noPrint">


Good luck!
0
 
arantiusCommented:
Prior comments are correct, but I just want to point out it can be done in one .css file, or even in an inline <style></style>:

.printOnly { display: none; }
.screenOnly { display: inline; }

@media print {
      .printOnly { display: inline; }
      .screenOnly { display: none; }
}

With any other changes that are appropriate.  I usually disable navigation bars in print view.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
FahdmurtazaCommented:
I think all above will work fine.

Reagrds
Fahd Murtaza
0
 
JpmSoftAuthor Commented:
Thanks to all of you guys!

Lets think about that situation:

What I'm designing is an HTML Reporting tool...
Each report with more than 1 page has a navigation bar to jump between pages.

All of this is working fine by using this method:

<DIV ID='PAGE_1' style='display:inline>
...
</DIV>
<DIV ID='PAGE_2' style='display:none'>
...
</DIV>

etc...

When I jump between pages I change the style.display property for each DIV element to their respective values.

This is just fine, but when I try to print,  those pages which are in state "display:none" are not being printed.

Now again...
How do you think I can make some pages not to be visible on screen but they can be printable at any time?

If I use ashleysdb's approach and set  up every <DIV> with 2 styles like:
<DIV ID='PAGE_1' class='print_visible_allways screen_visible'>
How could I change the screen_visible style when I want to show/hide a specific DIV (current page) ???


Thanks in advance!
JpmSoft


0
 
ashleydbCommented:
I'm not sure you would need to make that distinction when you set the display to none. The print style sheet may over-rule. Have you tried my method as it is already to see if it works?
0
 
FahdmurtazaCommented:
If we are not geeing a response of what he says about his problem, then go on deleting it.
Regards,
Fahd Murtaza
0
 
ashleydbCommented:
Well I gave a working responce, so what more can we do?
0
 
JpmSoftAuthor Commented:
Hi guys,

Sorry by the late....

After all, no one of your recommendations works for me...

What I decided to do was show all printable DIV's with the javascript function where I start the printing process... this way all the pages in the report could be printed and supported by the printing dialog.

This is not much elegant, but it works.

JpmSoft

0
 
FahdmurtazaCommented:
At least you should consider answers from ashleydb and others who worked for it.
Regards,
Fahd Murtaza
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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