Page 1 of 1

HOW to apply them without reload the page usng php?

Posted: Thu Apr 21, 2016 12:37 pm
by sndyroy
HI! can someone guide me that how to apply theme without reload the page? does it require ajax or not (if not) then how can i develop this sort of site.
thanks in advance.

Re: HOW to apply them without reload the page usng php?

Posted: Thu Apr 21, 2016 1:50 pm
by requinix
Depends how your theming works. Are you using separate CSS files? Are the themes set up ahead of time? How do they work?

My preferred way would probably be to change the href of the theme's <link>.

Code: Select all

<link id="theme-css" rel="stylesheet" type="text/css" href="/path/to/theme1.css">

Code: Select all

document.getElementById("theme-css").href = "/path/to/theme2.css"; // vanilla JS

Re: HOW to apply them without reload the page usng php?

Posted: Thu Apr 21, 2016 1:55 pm
by Christopher
That may not work in all browsers. I know I have had problems doing just that. You may need to load the stylesheet settings and apply them individually with Javascript initially. Thereafter the new stylesheet can be specificed.

Re: HOW to apply them without reload the page usng php?

Posted: Thu Apr 21, 2016 3:13 pm
by requinix
Figures. I'd also consider removing the <link> and adding a new one.

Ideally, though, I'd think that if the CSS for the themes wasn't that large and they were all known ahead of time then the best idea would be "namespacing" each with a class on the body, as in

Code: Select all

body.theme1 ... { }
body.theme1 ... { }

body.theme2 ... { }
body.theme2 ... { }

Code: Select all

<body class="theme1">
"Compiling" themes (eg, combining rules and minimizing) into one file would help. Less/Sass too.

Re: HOW to apply them without reload the page usng php?

Posted: Thu Apr 21, 2016 5:23 pm
by Christopher
The only thing I found that worked on all devices was to Ajax in the stylesheet with the content. I probably could have tried a few other things, but in my case it was only a small set of styles changing. Removing the <link> and adding a new one was next on my list. The namespacing idea sounds interesting.

Re: HOW to apply them without reload the page usng php?

Posted: Sun May 01, 2016 3:20 pm
by thinsoldier
Why exactly do you need to not reload the page?