Advertising - Credit Cards - Bob's Free Stuff Forum - Project Management Software - Internet Dating

PDA

View Full Version : Possible to detect which stylesheet in use?


mar2195
Nov 22nd 2006, 6:20 pm
Is it possible to use Javascript to detect which stylesheet is currently being used in a page?

... a script to detect the HREF value in the <link> tag which is located in the <HEAD> of the page.

IMPORTANT:
I need to place this javascript "detect" after the <BODY> tag! (= cannot place this script in the <HEAD>)

EXAMPLE:

<html>
<head>
<link rel="stylesheet" href="main.css" type="text/css">
</head>
<body>
blah, blah....
<script> detectCurrentStylesheetBeingUsed() </script>
</body>
</html>


My guess is that this cannot be done ... but I'd like to hear from others.


Thanks.

ajsa52
Nov 23rd 2006, 3:16 pm
Try this (works in Explorer and FireFox):


<script>
hr = document.getElementsByTagName("link")[0].getAttribute('href');
alert( hr );
</script>

mar2195
Nov 23rd 2006, 9:57 pm
Yep! This is the answer.

<script>
hr = document.getElementsByTagName("link")[0].getAttribute('href');
alert( hr );
</script>

Believe it or not, I almost had this. Stupidly, I was using [1], not [0]! That damn zero! That's why I wasn't getting MY alert to popup the the name of the style.

Anyway, thanks for your help! :D