NameSilo

CSS switcher

SpaceshipSpaceship
Watch

Bryan792

Established Member
Impact
0
Does anyone know the code to switch css with anchors and no javascript


Could you give it to me free
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
RIte now i am using

<link rel="alternate stylesheet" type="text/css" href="rockets.css" title="Rockets" media="all">

and

<a href="#" onclick="setActiveStyleSheet('Rockets');return false;" title="Switch to Rockets theme">Test</a>

but when i click on test the website just becomes home.html# from home.html and nothing has changed
 
0
•••
Yep, I got the code somewhere.

In the head put this

PHP:
<LINK href="blue.css" rel="alternate stylesheet" type="text/css" title="default" />
<link href="orange.css" rel="alternate stylesheet" type="text/css" title="orange" />
<link href="white.css" rel="alternate stylesheet" type="text/css" title="white" />
<link href="purple.css" rel="alternate stylesheet" type="text/css" title="purple" />


<script type="text/javascript" 
src="styleswitcher.js"></script>

Change where needed.


right now to change the styles.

This is the code (the code I shall show you uses images in the links, but feel free to use text.

PHP:
<a href="#" 
onclick="setActiveStyleSheet('default'); 
return false;"><img src="img/sticky_blue.gif" border=0></a>

<a href="#" 
onclick="setActiveStyleSheet('orange'); 
return false;"><img src="img/sticky_orange.gif" border=0></a>

<a href="#" 
onclick="setActiveStyleSheet('white'); 
return false;"><img src="img/sticky_white.gif" border=0></a>

<a href="#" 
onclick="setActiveStyleSheet('purple'); 
return false;"><img src="img/sticky_purple.gif" border=0></a>

Now here is "styleswitcher.js"

PHP:
function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);

Hope that helps you and other people

PJ
 
0
•••
So i have to use javascript??
 
0
•••
Well couldn't you make multiples of the page and just link to them? It would be a stupid idea unless your content doesn't change much. Sorry the only thing I can think of without javascript. Or your using php you can have the page reload in a different on I believe.
 
0
•••
1 more question.... since im going to use javascript how do i make the:

for(i=0; (a = document.getElementsByTagName("link")); i++)

in:

function setActiveStyleSheet(title) {
var i, a, main;
for(i=0; (a = document.getElementsByTagName("link")); i++) {
if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
a.disabled = true;
if(a.getAttribute("title") == title) a.disabled = false;
}
}
}


How do i make it find all the <link> in another page?
 
0
•••
I want it so I can make the link on 1 frame change the css on another frame
 
0
•••
CatchedCatched

We're social

Escrow.com
Spaceship
Rexus Domain
CryptoExchange.com
Domain Recover
CatchDoms
DomDB
NameFit
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back