473,401 Members | 2,127 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

Hidden Layer Print Problems

I have a piece of hidden text that the user can show/hide by clicking
on a link, the problem I have is that I would like the text to appear
when the page is printed.
I've used the @media print in my CSS, and this shows the text when the
page is printed without clicking on the link. However, if you show then
hide the text (by clicking the link twice) the text does not appear in
the print preview. It's as if the javascript is overriding the @media
rule. Is there any other way to achieve what I am trying to do, or is
it going to be impossible to display the hidden text when printed.

I've prepared a test page here:
http://www.pete-b.co.uk/printProblem.htm

I've have tested this on Firefox 1.0 and IE6, and any solution will
only have to work on these browsers as the page is for a company
intranet.

Bonnett

Jul 23 '05 #1
7 2704
Ivo
"Bonnett" wrote
I have a piece of hidden text that the user can show/hide by clicking
on a link, the problem I have is that I would like the text to appear
when the page is printed.
I've used the @media print in my CSS, and this shows the text when the
page is printed without clicking on the link. However, if you show then
hide the text (by clicking the link twice) the text does not appear in
the print preview. It's as if the javascript is overriding the @media
rule. Is there any other way to achieve what I am trying to do, or is
it going to be impossible to display the hidden text when printed.

I've prepared a test page here:
http://www.pete-b.co.uk/printProblem.htm

I've have tested this on Firefox 1.0 and IE6, and any solution will
only have to work on these browsers as the page is for a company
intranet.


The initial hide is done with a class, then the javascript modifies the
style.display directly. Of course that overrides the properties set by the
class: it is more specific and will win the CSS cascade.
If you have the javascript toggle a className (by the way, elements can have
more than one classes, eparate them with commas) instead of the style
itself, then all should be well.

This function should give some clues:

function toggleclass(el,name){
if(el.className===''||el.className.indexOf(name)<0 ) {
el.className+=' '+name;
} else {
el.className=el.className.replace(name,'');
}
}
--
Ivo
Jul 23 '05 #2
On Thu, 25 Nov 2004 12:40:59 +0100, Ivo <no@thank.you> wrote:

[snip]
(by the way, elements can have more than one classes, eparate them with
commas)


You mean separate them with *spaces*. Your code does that, but I thought I
should make sure there's no confusion.

[snip]

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #3
Ivo
"Michael Winter" wrote
On Thu, 25 Nov 2004 12:40:59 +0100, Ivo <no@thank.you> wrote:
(by the way, elements can have more than one classes, separate them
with commas)


You mean separate them with *spaces*. Your code does that, but I thought I
should make sure there's no confusion.

Darn. Typing too quickly again...
Thanks for pointing that out,
Ivo
Jul 23 '05 #4
Cheers, that was just what I was after, I've adapted your function to:

function showHide(id){
element = document.getElementById("description"+id);
element.className = (element.className == "show") ? "dontShow" :
"show";
}

with the CSS as:
..dontShow { display:none}
..show {display: inline }
@media print {
..dontShow { display:inline}
}

and the HTML to:
<a href="#" onclick="showHide(0); return false"
onkeypress="showHide(0); return false">Show Hidden Text</a>
<span class="dontShow" id="description0">
This is some hidden text
</span>
(I've used a unique number as the page will have numerous hidden parts)

Jul 23 '05 #5
Ivo
"Bonnett" wrote
Cheers, that was just what I was after, I've adapted your function to:

function showHide(id){
element = document.getElementById("description"+id);
element.className = (element.className == "show") ?
"dontShow" : "show";
}


Excellent. Only one more thing to make it perfect: "element" is now made a
global variable, a useless waste of memory. If you precede it in the first
statement with the keyword "var" it will be a local variable, existing only
in the the scope of the function. This will not affect what happens on
screen or on paper or anywhere else, but on a large page with many elements
with many id's and many variables, you may notice a difference in
performance. Like so:

var element = document.getElementById("description"+id);

--
Ivo
Jul 23 '05 #6
Ta very much, I've always wondered about the difference between whether
the "var" is specified or not.

--
Bonnett

Jul 23 '05 #7
Bonnett wrote:
I've used the @media print in my CSS, and this shows the text when the
page is printed without clicking on the link. However, if you show then
hide the text (by clicking the link twice) the text does not appear in
the print preview. It's as if the javascript is overriding the @media
rule. Is there any other way to achieve what I am trying to do, or is
it going to be impossible to display the hidden text when printed.


You may try:

@media print {
.described { display:inline !important }
}

Daniel
Jul 23 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Andrew | last post by:
I have a <div> section of text in my page that I want to make visible via an input check box associated with an OnClick javascript. I can do this OK but the problem is that the space for the hidden...
1
by: PAD | last post by:
I have written a javascript routine that populates a parent document with a series of <iframe>s. Each <iframe> receives its contents from a series of separate smaller HTML files. Of course my NN...
1
by: tabert | last post by:
I want to use JavaScript when a button is clicked to show and hide a SPAN or DIV. This works in both IE and Netscape, but what I'd like to happen is for there to be no white space where the hidden...
2
by: ckerns | last post by:
How can I check to see if a layer is visible? I have four layers and I want to check each to use in an if...then...else statement. tia
19
by: Holger Hasselbach | last post by:
- The value of the object allocated by the malloc function is used (7.20.3.3). - The value of any bytes in a new object allocated by the realloc function beyond the size of the old object are used...
4
by: Big Dave | last post by:
Does anyone have suggestions on how to best handle errors in business objects that are part of a business layer? For example: Public Class Person Private _name as string Public Property Name...
2
by: l!m!t | last post by:
Hello, I hope somebody can help me I have been at this for hours. I am new to JavaScript. I need a script to show a layer of hidden content only when on a certain URL. I have searched and...
1
by: gammajonny | last post by:
Im 14 yrs old and just make web sites for fun really, i use html css and java script at the moment but im just starting java. I live in Exeter in the uk. That me basicly. My first question is- ...
3
by: John Franklin | last post by:
Can someone please tell me how to print a single layer? Many thanks. John Franklin
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.