Solved

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

Posted on 2004-09-06
11
207 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 80 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 90 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 80 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
The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

 
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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

687 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