SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jun 2006
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    help with alt stylesheet loader function

    ive got two css link tags in my document head:
    <link rel="stylesheet" type="text/css" href="/css/default.no_js.css" />
    <link rel="alternate stylesheet" type="text/css" href="/css/default.js.css" />

    im running this in a .js:
    function setActiveStyleSheet() {
    if (!document.getElementsByTagName) return false;
    var i, a, main;
    for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1) {
    a.disabled = true;
    if(a.getAttribute("rel").indexOf("alt") != -1) {a.disabled = false;alert ("test");}
    }
    }
    }

    window.onload=function(){
    setActiveStyleSheet();
    }

    as you can see, ive got an alert in there to test if it finds the alt style sheet. it does, but that style sheet doesn't show up. what am i doing wrong?

    thanks,

    corey

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There's no problem with your function, but a link element with rel="alternate stylesheet" doesn't display as a stylesheet should.

    Looks like the NAME attribute is available to the LINK tag. Why not put name="main" or name="alternate" and test on that?

  3. #3
    SitePoint Member
    Join Date
    Jun 2006
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i tried changing both the rel attribute and adding a name. neither worked. since im hacking:
    http://www.alistapart.com/stories/alternate/
    i went back and tried their suggestion using title. that worked. thanks for putting me on the right path!

    my other question - does this even make sense? is there a better way to specify a style sheet if js is disabled?

    thanks,

    corey


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
  •