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.
HOW to apply them without reload the page usng php?
Moderator: General Moderators
Re: HOW to apply them without reload the page usng php?
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>.
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- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: HOW to apply them without reload the page usng php?
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.
(#10850)
Re: HOW to apply them without reload the page usng php?
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
"Compiling" themes (eg, combining rules and minimizing) into one file would help. Less/Sass too.
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">- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: HOW to apply them without reload the page usng php?
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.
(#10850)
-
thinsoldier
- Forum Contributor
- Posts: 367
- Joined: Fri Jul 20, 2007 11:29 am
- Contact:
Re: HOW to apply them without reload the page usng php?
Why exactly do you need to not reload the page?
Warning: I have no idea what I'm talking about.