...

View Full Version : StyleSwitch works local but not on server?



martynball
04-05-2009, 03:34 PM
I have added a style switching script to my website and it works fine run locally but will not do anything on the server, Why?



[/<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Martyn Lee Ball - 3D</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<link href="alt-styles/red.css" rel="alternate stylesheet" type="text/css" title="red">
<link href="alt-styles/green.css" rel="alternate stylesheet" type="text/css" title="green">
<link href="alt-styles/pink.css" rel="alternate stylesheet" type="text/css" title="pink">
<script type="text/javascript" src="styleswitcher.js"></script>
</head>
<body>
<a href="#"
onclick="setActiveStyleSheet('default'); return false;" rel="nofollow">Blue</a>
<a href="#"
onclick="setActiveStyleSheet('red'); return false;" rel="nofollow">Red</a>
<a href="#"
onclick="setActiveStyleSheet('green'); return false;" rel="nofollow">Green</a>
<a href="#"
onclick="setActiveStyleSheet('pink'); return false;" rel="nofollow">Pink</a>
<a name="top"></a>
<!--TITLE TABLE!-->
<table border="1" width="700" height="auto" align="center" bordercolor="#446688">
<td>
<div class="title">
<div align="center">MARTYN LEE BALL</div>
<div class="title-caption">THIS WEBSITE WILL CONTAIN ALL OF MY WORK WITHIN THE MDEIA TOPICS, SUCH AS: 3D MODELS, TEXTURES, ANIMATIONS, ECT... PLEASE CHECK BACK FOR UPDATES, AS I WILL UPDATE WHEN EVER I CREATE SOMETHING NEW.</div>
</div>
</td>
<tr></tr>
</table>
<!--TITLE TABLE END!-->
&nbsp; &nbsp;
<table class="navbar" width="700" align="center" border="0">
<tr>
<td>
<div class="navbar-text" align="center">
<a href="index.php">Home</a> |
<a href="3d.php">3D Models</a>(15) |
<a href="textures.php">Textures</a>(0) |
<a href="2d.php">2D Work</a>(0) |
<a href="other.php">Other</a>(0) |
<a href="contactme.php">Contact Me</a> |
<a href="about.php">About</a>
</div>
</tr>
</td>
</table>
<table class="content" width="700" align="center" border="0">
<tr>
<td rowspan="2">
<div class="update">
UPDATED: THURDAY, 02 APRIL 2009
</div>
<div id="txt"></div>
<div class="main-content-title">
3D Models
</div>
<div class="main-content">
These are my 3D models. I will add the newest at the top of the page.
</div>
<?php include "pages/h3hornet.html"; ?>
<!--Break!--><?php include "pages/break.html"; ?> <!--Break!-->
<?php include "pages/h3odstsmg.html"; ?>
<!--Break!--><?php include "pages/break.html"; ?> <!--Break!-->
<?php include "pages/h3missilepod.html"; ?>
<!--Break!--><?php include "pages/break.html"; ?> <!--Break!-->
</td>
</table>
<table class="copyright" width="700" align="center" border="0">
<div class="update" align="center">&copy; COPYRIGHT - MARTYN LEE BALL - 2009</div>
</table>
<center>
<div class="ads">
<a href="http://www.modacity.net" target="_blank"><img src="images/modacity.jpeg"></a>
<a href="http://www.halomaps.org" target="_blank"><img src="images/halomaps.jpeg"></a>
<a href="http://www.modhalo.net/" target="_blank"><img src="images/modhalo.gif"></a>
<a href="http://www.deviantart.com/" target="_blank"><img src="images/deviantart.jpeg"></a>
</div>
</center>
<?php include "side-bar.html"; ?>
</body>
</html>

abduraooft
04-05-2009, 03:48 PM
<link href="alt-styles/green.css"
Have you uploaded your stylesheets to their corresponding paths? Could you post a link to your page?

martynball
04-06-2009, 01:16 PM
http://martynleeball.nxserve.net/martynball/

http://i58.photobucket.com/albums/g268/martynball/styelswitcher.jpg

abduraooft
04-06-2009, 02:28 PM
Your script has an error,

missing ; before statement
Get a copy of firebug for your firefox. I think you have made a mistake while compressing(removing all line breaks in) your javascript, some where at the end.

martynball
04-06-2009, 02:29 PM
I havnt touched the javascript. I just uploaded it. Why was it working locally though?

abduraooft
04-06-2009, 02:37 PM
I havnt touched the javascript. I just uploaded it. Why was it working locally though?
No idea about your local files :), but in the above given url, there is an error. Have a try by uploading the script from ALA(hope you've got it from there) directly, without making any compression.

martynball
04-06-2009, 02:40 PM
Dont think I got it from there. Do you have a link?

abduraooft
04-06-2009, 02:40 PM
http://www.alistapart.com/articles/alternate/

martynball
04-06-2009, 02:44 PM
I just tryed that, didnt work. So I put the javascript into the actualy page. And it works. Am I linking to the javascript wrong?

abduraooft
04-06-2009, 02:50 PM
When I just put all the codes provided in that website as such, like

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 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;
}
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;
}
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);
}
it works. That's all I know.
(I'm running out of time, no way to decompress your current script and isolate the issue, right now :) )

F-b0mb
04-06-2009, 02:56 PM
Your style sheet tags aren't properly closed.

<link href="alt-styles/red.css" rel="alternate stylesheet" type="text/css" title="red"/>
<link href="alt-styles/green.css" rel="alternate stylesheet" type="text/css" title="green"/>
<link href="alt-styles/pink.css" rel="alternate stylesheet" type="text/css" title="pink"/>

martynball
04-06-2009, 02:57 PM
I opened the javascript file and pasted in what you put abduraooft and it works now, thanks. I will make sure they are closed right as well F-b0mb. Thanks.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum