webcodebase.com Snippets database & Pastebin

Change style without Reloading (PHP+JS+CSS)

Submitted on 18/09/2008
Authors Comment: Ever wanted to give your users the possibility to change styles without reloading? This simple PHP+Javascript can help you achive that.
How to use:
Just edit it to fit your needs :)

You need to make 3 files.

The first you should name index.PHP

the other 2 are CSS files and must be saved as this:

style/black/style.css

and

style/white/style.css

Enjoy.
Download Snippet:
Snippet:

  1. <html>
  2.         </head>
  3.                 <link id="st" <?php
  4.                         if (isset($_COOKIE['st'])) {
  5.                                 echo 'href="style/'.$_COOKIE['st'].'/style.css"';
  6.                         } else {
  7.                                 echo 'href="style/white/style.css"';
  8.                         }
  9.                 ?>  rel="stylesheet" type="text/css" />
  10.                 <script type="text/javascript">
  11.                         function change(style){  
  12.                                  // Change the href of style
  13.                                 document.getElementById("st").href = "style/" + style + "/style.css";
  14.                                 // Set cookie "st"
  15.                                 var expiresdate=new Date();
  16.                                 expiresdate.setDate(expiresdate.getDate()+360);
  17.                                 document.cookie="st="+style+" ;expires="+expiresdate.toGMTString();
  18.                         }
  19.                 </script>
  20.         </head>
  21.         <body>
  22.         Text <br /><br /><br />
  23.         <!-- Buttons for changing the style -->
  24.         <input type="button" onclick="change('black')" value="black" />
  25.         <input type="button" onclick="change('white')" value="white" />
  26.         </body>
  27. </html>
  28.  
  29. -------------------------------------------
  30. //  Testing code for style/black/style.css
  31.  
  32. body {
  33.         background-color: black;
  34.         color: purple;
  35. }
  36.  
  37. -------------------------------------------
  38. //  Testing code for style/white/style.css
  39.  
  40. body {
  41.         background-color: white;
  42.         color: lime;
  43. }

 

Comments:

  1. .hrgqgno | December 11, 2008 at 18:47

    QxqXjC <a href="http://ccefpzaihuhd.com/">ccefpzaihuhd</a>, [url=http://rytcadhzwqdo.com/]rytcadhzwqdo[/url], [link=http://zdzbyaklgeig.com/]zdzbyaklgeig[/link], http://yblvjsxfpdru.com/

  2. .cgdmerirom | December 11, 2008 at 18:47

    DSFdto <a href="http://xtlnqddcdxee.com/">xtlnqddcdxee</a>, [url=http://vcygvmzfcaow.com/]vcygvmzfcaow[/url], [link=http://rchaogvryenl.com/]rchaogvryenl[/link], http://dtvovaspjmbc.com/

  3. .zxrrbsh | December 11, 2008 at 18:47

    OaAC4i <a href="http://ejwrxotwwnhh.com/">ejwrxotwwnhh</a>, [url=http://vfjwiludljfm.com/]vfjwiludljfm[/url], [link=http://lvdtkjmywvsy.com/]lvdtkjmywvsy[/link], http://hsepitwgogce.com/

  4. .iqwmjubtmk | December 11, 2008 at 18:47

    Rriywt <a href="http://ejwopxncsabc.com/">ejwopxncsabc</a>, [url=http://yukldtxaxduc.com/]yukldtxaxduc[/url], [link=http://luokluzgztyz.com/]luokluzgztyz[/link], http://hibsffgfhulk.com/

  5. .dpknix | December 11, 2008 at 18:47

    VuNpSI <a href="http://zttrzjbgugil.com/">zttrzjbgugil</a>, [url=http://xkzxpbtjgatc.com/]xkzxpbtjgatc[/url], [link=http://qexeeebbwobj.com/]qexeeebbwobj[/link], http://hurbmcftcffa.com/

  6. .nfipgtdpkt | December 11, 2008 at 18:47

    uFu0B9 <a href="http://nzzplhbrzhpp.com/">nzzplhbrzhpp</a>, [url=http://rpcfdirfeygw.com/]rpcfdirfeygw[/url], [link=http://hpiopuulfofh.com/]hpiopuulfofh[/link], http://meobecqsjhky.com/

  7. .evzfoamgqdo | December 11, 2008 at 18:47

    v4R1GU <a href="http://qvsgvzaejebq.com/">qvsgvzaejebq</a>, [url=http://gvkeazrjpruz.com/]gvkeazrjpruz[/url], [link=http://kalswwfwdojl.com/]kalswwfwdojl[/link], http://myrdyubqmiox.com/


New Comment:
Name:
Comment:








Latest News

  • 30/12/09
    Webcodebase is BACK & New updates.
    Hello, Because of a jackass of a friend the main files for Webcodebase was deleted. I Thought everything was lost until i found a backup folder on my old linux box, so i restored WCB Back to its original state. The staff will continue posting snippets and fighting spam. We will also start releasing tools that web masters can use to check their scripts for vulnerabilities. These scripts will have special stars next to them and the "STAFF" tag. Please use these on your own systems only, we are NOT responsible for any damage they may do. We release them purely for educational purposes only! Thanks, Head of WCB, Arne AKA Cypher....
    [Read More]