Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 356801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T12:08:45+00:00 2026-05-12T12:08:45+00:00

I’ve been developing a site (for now is here as an example: http://neurotoxine.mine.nu/gloom ),

  • 0

I’ve been developing a site (for now is here as an example: http://neurotoxine.mine.nu/gloom), and I’m getting a strange behaviour from a styleswitcher code. It’s big so please be patient.

First, you may go to the site I appointed first and see it.
What you’ve got there, it’s a joomla page, with a Jquery using

var $j = jQuery.noConflict();

in order to avoid mootools conflicts.
Then, I used these:

<?  // Checks for, and assigns cookie to local variable:
if(isset($_COOKIE['style']))
{   $style = $_COOKIE['style'];
}
// If no cookie is present then set style as "red" (default):
else {    $style = 'red';
}
?>

This is just for the cookie setting, if the cookie is not set then $style=red, and this variable will be appended to the CSS. Like this:

<link rel="stylesheet" type="text/css" href="<?php echo $this->baseurl ?>/templates/wh1/css/template_<?php echo $style ?>.css" media="screen" />

The first code, $this->baseurl=directory for joomla installation, in this case gloom.
The second one, echo $style, will write the cookie loaded value or the value assigned from the options, in the case you get there for first time then you’ll got RED as value then, template_red.css will be the CSS for the entire site.

There’s a JS, that works doing some jquery tricks:

 jQuery.fn.styleSwitcher = function(){
  $j(this).click(function(){
      // We're passing this element object through to the loadStyleSheet function.
      loadStyleSheet(this);
      // And then we're returning false.
      return false;
  });
  function loadStyleSheet(obj) {
    $j('#preloader')
    // Now fade in the div (#preloader):
    .fadeIn(500,function(){
      // The following will happen when the div has finished fading in:
      // Request PHP script (obj.href) with appended "js" query string item:
      $j.get( obj.href+'&js',function(data){
        // Select link element in HEAD of document (#stylesheet) and change href attribute:
        $j('#stylesheet').attr('href','css/' + data + '.css');
        // Check if new CSS StyleSheet has loaded:
        cssDummy.check(function(){
          // When StyleSheet has loaded, fade out and remove the #overlay div:
          $j('#preloader').fadeOut(500);
        });
      });
    });
  }
  // CSS DUMMY SECTION
  var cssDummy = {
    init: function(){
      // Appends "dummy-element" div to body:
      $j('<div id="dummy-element" style="display:none" />').appendTo('body');
    },
    check: function(callback) {
      // Checks if computed width equals that which is defined in the StyleSheets (2px):
      if ($j('#dummy-element').width()==2) callback();
      // If it has not loaded yet then simple re-initiate this function every 200 milliseconds until it had loaded:
      else setTimeout(function(){cssDummy.check(callback)}, 200);
    }
  }
  cssDummy.init(); }

then, I start the function in my page:

$j(document).ready(function(){
$j('#style-switcher a').styleSwitcher();
});

and I call it from a link like this:

<a href="<?php echo $this->baseurl ?>/templates/wh1/style-switcher.php?style=fire">img</a>

Finally, the styleswitcher.php code is here:

<?php
$style = $_GET['style'];
setcookie("style", $style, time()+604800*24); // 604800 = amount of seconds in one week *4=1 month *24=1/2 year *48=1 year
if(isset($_GET['js']))
echo $style;
else header("Location: ".$_SERVER["HTTP_REFERER"]); ?>

Now, the problem is, that when I tested this in a site, everything worked fine (http://neurotoxine.mine.nu/wht/index-test.php – The links for the stylechanger are in the top and left of them says THEMES). But when I inserted the whole code in joomla template, the whole system failed. I did some fixes here and there (mainly the $j declaration) and then I realized that could be something related to the path of the templates, so I tested many types of declarations, absolute paths, relative paths, etc. and nothing happens.

Then I copied styleswitcher.php to the root of joomla (neurotoxine.mine.nu/gloom) and checked if ti would work there, and I’m getting a blank page. I clicked go-back and then WOW the stylechanger worked, but then something isn’t telling where to go back to I think it could be the header(“Location: “.$_SERVER[“HTTP_REFERER”]); instruction, but I don’t know what to change there to make it work.

Joomla gives a declaration in the header for its templates:

<base href="http://neurotoxine.mine.nu/gloom/" />

I don’t know if this is doing something to the way the http_referer works, but I disabled this and the site still does the same, click a style, page blank, hit go-back and voila, the style has changed but failed to retrieve the page where I was.

Some ideas? Any help could be useful.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T12:08:45+00:00Added an answer on May 12, 2026 at 12:08 pm

    I resolved this… the solutions were fixing three to four errors:

    first of all, the cookie checker in the html should have asked if the coockie wasn’t empty, no if it was SET. So:

    <?php  // Checks for, and assigns cookie to local variable:
    if(!empty($_COOKIE['style'])) $style = $_COOKIE['style'];
    // If no cookie is present then set style as "red" (default):
    else $style = 'red';
    ?>
    

    That was the first thing to fix.
    Then this line is fixed, because the JQuery plugin asked for an ID in the header to alter. I didn’t realized I haven’t an ID at the link stylesheet declaration

    <link id="stylesheet" rel="stylesheet" type="text/css" href="<?php echo $this->baseurl ?>/templates/wh1/css/template_<?php echo $style ?>.css" media="screen" />
    

    In this line I also discovered that

    <?php echo $this->baseurl ?>
    

    should be replaced with the base address but, without the domain, so it should be

    /gloom/templates/wh1/css/template_<?php echo $style ?>.css
    

    Also, in the initialization of the JQuery plugin, i made a fatal mistake. I didn’t changed the ID for the container of the tag that was going to be captured by the plugin. That was in part for the confusion between the ID on the header for the stylesheet and the ID on the tag container. So I used “#tselect” for the ID of a DIV and it solved the Jquery work. Besides, is mandatory to ad $j in every statement of the plugin.

    $j(document).ready(function(){
        $j.preloadCssImages({statusTextEl: '#textStatus', statusBarEl: '#status'});
            $j("img#hhead").toggle(
            function () { 
                $j("#headtop").slideDown();
            },
            function () {
                $j("#headtop").slideUp();
            });
        $j("#tselect a").styleSwitcher(); // here is the "ID TAG".plugin() call.
    });
    

    Now, in the styleswitcher.php I used a tip someone told me about the cookie:

    <?php $style = $_GET['style'];
    setcookie("style", $style, time()+604800,"/"); // 604800 = amount of seconds in one week
    if(isset($_GET['js'])) echo $style;
    else header("Location: ".$_SERVER['HTTP_REFERER']);
    ?>
    

    Did you noticed? is a simple / slash.

    Now everything works fine. The stylechanger changes the styles and the JQuery effects work.
    You could see it here: link text

    If anyone wants the files and an explanation, send me a message.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm looking for suggestions for debugging... If you view this site in Firefox or
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
Seemingly simple, but I cannot find anything relevant on the web. What is the
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.