Possible to detect which stylesheet in use?

Discussion in 'JavaScript' started by mar2195, Nov 22, 2006.

  1. #1
    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>
    
    Code (markup):
    My guess is that this cannot be done ... but I'd like to hear from others.


    Thanks.
     
    mar2195, Nov 22, 2006 IP
  2. ajsa52

    ajsa52 Well-Known Member

    Messages:
    3,426
    Likes Received:
    125
    Best Answers:
    0
    Trophy Points:
    160
    #2
    Try this (works in Explorer and FireFox):

    
    <script>
    hr = document.getElementsByTagName("link")[0].getAttribute('href');
    alert( hr );
    </script>
    
    Code (markup):
     
    ajsa52, Nov 23, 2006 IP
  3. mar2195

    mar2195 Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Yep! This is the answer.

    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
     
    mar2195, Nov 23, 2006 IP