Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    Victoria, BC, Canada
    Posts
    962
    Thanks
    0
    Thanked 1 Time in 1 Post

    Changing stylesheets dynamically

    I've seen it done, but I don't know HOW it was done. I'd like to add the option to change stylessheets on my site, so the user can click a link to change the current stylesheet. I can do the stylesheet itself, but HOW would I change it? Javascipt?

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Montreal, Canada
    Posts
    644
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Tested in IE6/Moz1.2b

    Code:
    <html>
    
    <head>
    <LINK id="stylecss" REL=StyleSheet HREF="mystyle.css" TYPE="text/css" MEDIA=screen>
    </head>
    
    <body>
    This is my text <a href="javascript: document.getElementById('stylecss').setAttribute('href','mystyle2.css');">LINK</a>
    </body>
    
    </html>
    Last edited by x_goose_x; 11-26-2002 at 03:33 AM.

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    Victoria, BC, Canada
    Posts
    962
    Thanks
    0
    Thanked 1 Time in 1 Post
    Would that apply to the whole site, or just that one page? Is there a way to make that style selection apply to the whole site until the viewer leaves or changes the style back?

  • #4
    jtr
    jtr is offline
    New Coder
    Join Date
    Jun 2002
    Location
    Northern California
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Maybe something like this.

    http://www.web-sn.com/scrpts/skinner/

  • #5
    Senior Coder joh6nn's Avatar
    Join Date
    Jun 2002
    Location
    72° W. 48' 57" , 41° N. 32' 04"
    Posts
    1,887
    Thanks
    0
    Thanked 1 Time in 1 Post
    bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

    i am a loser geek, crazy with an evil streak,
    yes i do believe there is a violent thing inside of me.

  • #6
    Regular Coder
    Join Date
    Jun 2002
    Posts
    185
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here's how I did it on my site, using ASP on the server:

    http://www.brainjar.com/asp/schemes/

    Whether you do it client-side or server-side, you'll probably want to save the user's selection using a cookie so it can be applied to all pages on your site.

  • #7
    Regular Coder
    Join Date
    Jun 2002
    Location
    NL
    Posts
    421
    Thanks
    0
    Thanked 0 Times in 0 Posts


  •  

    Posting Permissions

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