SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict Huscy's Avatar
    Join Date
    Jul 2002
    Location
    Newcastle, UK
    Posts
    318
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Trying to get a grasp... (newbie question)

    Im trying to get a grasp on what javascript can do, now ive got a (massive) list of all the objects, and it is my understanding that document.styleSheet.href should be the styleseet filename - is this correct? if so, why doesnt this script display the filename?

    Code:
    <link rel="stylesheet" type="text/css" href="style.css">
    <script language="JavaScript" type="text/javascript">
    <!--
    
    var stylesheetSrc = document.styleSheet.href
    document.write(stylesheetSrc);
    
    //--->
    </script>
    can someone explain how this would be done?

  2. #2
    SitePoint Addict xDev's Avatar
    Join Date
    Jul 2003
    Location
    Moncton, New Brunswick, Canada
    Posts
    247
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    You almost had the right syntax, it's document.styleSheets[] - a collection array.

    Try this:

    Code:
    <html>
    <head>
    <link rel="stylesheet" type="text/css" href="style0.css">
    <link rel="stylesheet" type="text/css" href="style1.css">
    <link rel="stylesheet" type="text/css" href="style2.css">
    <script type="text/javascript">
    <!--
    
    function getSheetInfo()
    {
      var 
        styles = document.styleSheets,
        sLen = styles.length,
        styleHrefs = "";
    
      for(var i = 0; i < sLen; i++)
      {
        styleHrefs += 'stylesheet '+i+': "' + styles[i].href + '"\n'
      }
      alert(styleHrefs);
    }
    
    
    //--->
    </script>
    
    </head>
    <body>
    <a href="#" onclick="getSheetInfo(); return false;">get sheet info</a>
    </body>
    </html>
    Some good info here on this subject:
    http://www.xs4all.nl/~ppk/js/w3c/stylesheets.html

    Hope this helps,
    - xDev


    Quote Originally Posted by Huscy
    Im trying to get a grasp on what javascript can do, now ive got a (massive) list of all the objects, and it is my understanding that document.styleSheet.href should be the styleseet filename - is this correct? if so, why doesnt this script display the filename?

    Code:
    <link rel="stylesheet" type="text/css" href="style.css">
    <script language="JavaScript" type="text/javascript">
    <!--
    
    var stylesheetSrc = document.styleSheet.href
    document.write(stylesheetSrc);
    
    //--->
    </script>
    can someone explain how this would be done?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •