Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-29-2005, 04:05 PM   PM User | #1
Sayonara
Regular Coder

 
Sayonara's Avatar
 
Join Date: Oct 2004
Location: UK
Posts: 256
Thanks: 0
Thanked 0 Times in 0 Posts
Sayonara is an unknown quantity at this point
Detecting the Stylesheet in Use

Each page on this site I'm working on uses Stewart Rosenberger's Dynamic Text Replacement Script to replace the content of h1 and h2 tags with dynamically-generated images (without changing the page structure, for accessibility reasons.)

Normally, a visitor would follow the link for "Text Only" to turn off the image replacement script, and swap the preferred stylesheet with a text-only stylesheet.

However, if a visitor switches to the alternate text stylesheet using their client, the image generator script is not disabled.

What I want to know is, can JavaScript be used to detect the stylesheet that the client is currently using?

If so I will be able to turn off the DTR script, and I won't need to remove the option of having the alternate style sheet.
__________________
Quote:
Originally Posted by liorean
Just remember that you code for the user, and the user visits you because what you code is good.
Sayonara is offline   Reply With Quote
Old 01-29-2005, 07:49 PM   PM User | #2
Puffin the Erb
Regular Coder

 
Join Date: Oct 2004
Posts: 168
Thanks: 0
Thanked 5 Times in 5 Posts
Puffin the Erb is an unknown quantity at this point
The following syntax will return false if a particular StyleSheet is applied, true if not, where 'index' is the position of the StyleSheet, you are checking for, in the styleSheets array:

document.styleSheets[index].disabled;

Last edited by Puffin the Erb; 01-29-2005 at 08:00 PM..
Puffin the Erb is offline   Reply With Quote
Old 01-29-2005, 08:15 PM   PM User | #3
Sayonara
Regular Coder

 
Sayonara's Avatar
 
Join Date: Oct 2004
Location: UK
Posts: 256
Thanks: 0
Thanked 0 Times in 0 Posts
Sayonara is an unknown quantity at this point
That looks like just the thing, thanks

Can I print the stylesheets array to the screen for reference?
__________________
Quote:
Originally Posted by liorean
Just remember that you code for the user, and the user visits you because what you code is good.
Sayonara is offline   Reply With Quote
Old 01-29-2005, 08:28 PM   PM User | #4
Sayonara
Regular Coder

 
Sayonara's Avatar
 
Join Date: Oct 2004
Location: UK
Posts: 256
Thanks: 0
Thanked 0 Times in 0 Posts
Sayonara is an unknown quantity at this point
Ah, I found this, which looks useful:
http://www.quirksmode.org/dom/w3c_css.html
__________________
Quote:
Originally Posted by liorean
Just remember that you code for the user, and the user visits you because what you code is good.
Sayonara is offline   Reply With Quote
Old 01-29-2005, 08:51 PM   PM User | #5
Puffin the Erb
Regular Coder

 
Join Date: Oct 2004
Posts: 168
Thanks: 0
Thanked 5 Times in 5 Posts
Puffin the Erb is an unknown quantity at this point
You could list style details thus :

function displayStyles()
{
var cssFiles = "";
for(i=0;i<document.styleSheets.length;i++)
{
// get rid of initial part of URI as it may exceed alert box dimensions
var nextStyle = document.styleSheets[i].href.split("/") ;

cssFiles += nextStyle[nextStyle.length-1] + " [ " + document.styleSheets[i].title + " ]" + "\n";
}
alert(cssFiles);
}
Puffin the Erb is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:11 AM.


Advertisement
Log in to turn off these ads.