Welcome to the Geeks & God Static Archive. Read more »

Switching CSS styles

Joined: 11/28/2008

Hi folks

Is there any reason why they css swtiching technique here

http://www.codelifter.com/main/javascript/changestyles.html

could not be applied to what I need.

Which is:

a. A page has several news releases on it
b. I want to offer people the change to print just ONE of those news releases if they wish
c. To do this, a print-only css sheet would be activated for that particular news release, by clicking a button
d. Ideally, that button would also activate the browser print option at the same time.
e. Thus there would be several alternate print style sheets, each picking up only only a single news release.

Does that seem a practical thing? Is there a better way of doing it?

Blessings

Tony

Online outreach:
Internet Evangelism Day
Helping church websites:
Church Websites

Joined: 11/28/2008
It certainly sounds very

It certainly sounds very neat. I just hope the browser support is good.

Paul Davey
Whitford Church
"Everyone who calls on the name of the Lord will be saved." Romans 10:13
"For all have sinned and fall short of the glory of God, and are justified

bob
bob's picture
Joined: 11/28/2008
Yes, it is a neat idea and it

Yes, it is a neat idea and it should work for you. As for browser support, whenever you're working with javascript (even styles), you'll need to really test things out. If you're willing to throw in some server-side scripting, you might want to "program" dynamic stylesheets instead of having a different one for each article (if I understood you correctly). For the sake of code-wise efficiency, a standard print-version page might be better, though.

Joined: 11/28/2008
Well, I've tried it but run

Well, I've tried it but run into a bit of a problem. My code on the page head is

CODE
<link rel="stylesheet" type="text/css" media="print" href="style_1.css">
<link rel="stylesheet" type="text/css" media="print" href="style_2.css">
<link rel="stylesheet" type="text/css" media="print" href="style_3.css">
<link rel="stylesheet" type="text/css" media="print" href="style_1.css">

<script language="JavaScript">
<!--
var doAlerts=true;
function changeSheets(whichSheet){
 whichSheet=whichSheet-1;
 if(document.styleSheets){
   var c = document.styleSheets.length;
   if (doAlerts) alert('Change to Style '+(whichSheet+1));
   for(var i=0;i<c;i++){
     if(i!=whichSheet){
       document.styleSheets[i].disabled=true;
     }else{
       document.styleSheets[i].disabled=false;
     }
   }
 }
}
//-->
</script>

and the code for the style sheet change on the page is

CODE
<a href="JavaScript:changeSheets(2)">Print this item</a>

However, the code is designed to switch normal style sheets, not print style sheets. If you try and do a switch, it substitutes one of the alternate print style sheets as a monitor-display style sheet

Is there any way of adjusting the javascript so it knows that the change only applies to print media style sheets?

Blessings and thanks

Tony

Online outreach:
Internet Evangelism Day
Helping church websites:
Church Websites

Joined: 11/28/2008
I can't get that script to

I can't get that script to work - it always chose the last print style sheet in the header.

However, I have found a different @import method, where the print style sheets are not in the header, and so cannot superimpose themselves when not wanted. It is descripted here:

http://www.notestips.com/80256B3A007F2692/...C1?OpenDocument

It works for me with a drop down list. All, I think, that I need to change, is

<select class="select2" onchange="var v=this.options[this.selectedIndex].value; if (v != '') selectStyle('style', v);">

into an onclick hyperlink on just an onclick word, eg something like

<span style="cursor:help;" onClick='var v=this.options[this.selectedIndex].value; if (v != '') selectStyle('style', v);'>Print</span>

(which doesn't display, cos I haven't got it right.

How can I make that link?

Thanks for your ideas!

Blessings

tony

Online outreach:
Internet Evangelism Day
Helping church websites:
Church Websites

Joined: 11/28/2008
PS sorry, what I should have

PS sorry, what I should have said was, how can I combine

<select class="select2" style="width:165px" onchange="var v=this.options[this.selectedIndex].value; if (v != '') selectStyle('style', v);">

WITH

<option value="style-a">Style A</option>

into a single onclick action!

Blessings

Tony

Online outreach:
Internet Evangelism Day
Helping church websites:
Church Websites

Joined: 11/28/2008
PPSI suspect on reflection it

PPS

I suspect on reflection it would be easier in PHP.

I have seen something similar described here:
http://forums.devshed.com/showthread.php?p...ed=1#post816969

What I'd want it to do is:

1. You click on a link or form button
2. That writes the URL of the new print style sheet onto the page, presumably after the page refreshes.

I assume that a form would do it.

Any thoughts?

Blessings and thanks

Tony

Online outreach:
Internet Evangelism Day
Helping church websites:
Church Websites