• 0

Best way to code a theme switcher


Question

I don't know what to google so I haven't really found anything but I'm building a website that I would like to have a theme switched. Something like what neowin and other sites have been doing with the light / dark switcher.

I would think JavaScript would be the best way for it to be "on the fly" but how would I store that for the current user? Would it be a cookie? Some kind of session file so if that user comes back it's remember?

I don't know what the best practice would be. Finally getting back into coding websites / web development / app development. It's been awhile.

I hope someone out there can help!

Link to comment
Share on other sites

7 answers to this question

Recommended Posts

  • 0

a couple of ways.   

1) Session based if using php or asp
2) Cookies for persistance
3) Save to a user profile on a database. 

From there you can just use jquery to modify the included css file using the inner html function.

Link to comment
Share on other sites

  • 0

Thanks for the tips guys. Firey that's exactly what I was thinking.

I think I might do both cookies and session based so if people wanna browse the site but don't want to login they can still choose a theme

Link to comment
Share on other sites

  • 0

Thanks for the tips guys. Firey that's exactly what I was thinking.

I think I might do both cookies and session based so if people wanna browse the site but don't want to login they can still choose a theme

Aren't cookies required anyway? Since sessions are closed when a browser is closed(If I remember correctly).

Link to comment
Share on other sites

  • 0

@Seahorsepip: ncc is right. I am talking about a php session which is stored in the database.

 

a php session is stored on the php server, and only exists for as long as is configured on the server.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.