?
Solved

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

Posted on 2004-09-06
11
Medium Priority
?
209 Views
Last Modified: 2010-05-18
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
Comment
Question by:JpmSoft
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +2
11 Comments
 

Assisted Solution

by:Rahulkumar007
Rahulkumar007 earned 160 total points
ID: 11994039
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
 
LVL 3

Accepted Solution

by:
ashleydb earned 180 total points
ID: 11995881
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
 
LVL 18

Assisted Solution

by:arantius
arantius earned 160 total points
ID: 11997333
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
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 
LVL 6

Expert Comment

by:Fahdmurtaza
ID: 11999110
I think all above will work fine.

Reagrds
Fahd Murtaza
0
 
LVL 4

Author Comment

by:JpmSoft
ID: 12002423
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
 
LVL 3

Expert Comment

by:ashleydb
ID: 12004642
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
 
LVL 6

Expert Comment

by:Fahdmurtaza
ID: 12502011
If we are not geeing a response of what he says about his problem, then go on deleting it.
Regards,
Fahd Murtaza
0
 
LVL 3

Expert Comment

by:ashleydb
ID: 12508132
Well I gave a working responce, so what more can we do?
0
 
LVL 4

Author Comment

by:JpmSoft
ID: 12508532
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
 
LVL 6

Expert Comment

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

Featured Post

Learn by Doing. Anytime. Anywhere.

Do you like to learn by doing?
Our labs and exercises give you the chance to do just that: Learn by performing actions on real environments.

Hands-on, scenario-based labs give you experience on real environments provided by us so you don't have to worry about breaking anything.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article was originally published on Monitis Blog, you can check it here . Today it’s fairly well known that high-performing websites and applications bring in more visitors, higher SEO, and ultimately more sales. By the same token, downtime…
Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question