HOW to apply them without reload the page usng php?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sndyroy
Forum Newbie
Posts: 1
Joined: Thu Apr 21, 2016 12:28 pm

HOW to apply them without reload the page usng php?

Post 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.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

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

Post 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
User avatar
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?

Post 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.
(#10850)
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

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

Post 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.
User avatar
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?

Post 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.
(#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?

Post by thinsoldier »

Why exactly do you need to not reload the page?
Warning: I have no idea what I'm talking about.
Post Reply