Forum Moderators: not2easy

Message Too Old, No Replies

css for now js

         

eville84

4:11 pm on Feb 12, 2007 (gmt 0)

10+ Year Member



hi all

i am having problems creating an alternative style sheet for web site vistors that dont have java script.

I am doing A/B testing on a site that pushes style sheets in via javascript. Visitors that don't have a javascript enabled browser don't get the css file a/b pushes. So i need a style sheet that will be disabled with javascript and enabled without.

I tried using the alternative style sheet used here: [snip] . It works but ends up flashing the alternative style sheet quickly (then goes away) with vistors that do have javascript enabled.

Does anyone know of a good method to have an alternative style sheet that can be enabled on non javascript browsers?

[edited by: SuzyUK at 1:29 pm (utc) on Feb. 13, 2007]
[edit reason] Please no URLs : see TOS #13 [WebmasterWorld.com] [/edit]

Fotiman

5:37 pm on Feb 12, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Just wrap the stylesheet with the <noscript> element. For example, in the <head> of your document:

<noscript>
<link rel="stylesheet" type="text/css" href="noscript.css">
</noscript>

eville84

7:26 pm on Feb 13, 2007 (gmt 0)

10+ Year Member



Thanks. That worked flawlessly.

I am now trying to do a similar thing but this time with browsers that have cookies disabled.

I found a js script that can detect cookies. I am trying to write a conditional statement to serve a css file when it detects a cookie disabled browser.

I have very little javascript experience so please dont laugh at the last function i added at the bottom of this code:


// Cookie Library

function setCookie(name, value, expires, path, domain, secure) {
var curCookie = name + "=" + escape(value) + ((expires)? "; expires=" + expires.toGMTString() : "") + ((path)? "; path=" + path : "; path=/") + ((domain)? "; domain=" + domain : "") + ((secure)? "; secure" : "");
document.cookie = curCookie;
}

function getCookie(n) {
var d = document.cookie;
var p = n + "=";
var b = d.indexOf("; " + p);
if (b == -1) {
b = d.indexOf(p);
if (b!= 0) return null;
}
else b += 2;
var f = document.cookie.indexOf(";", b);
if (f == -1) f = d.length;
return unescape(d.substring(b + p.length, f));
}

function deleteCookie(name, path, domain) {
var v = getCookie(name);
if (v!= null) document.cookie = name + "=" + ((path)? "; path=" + path : "") + ((domain)? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
return v;
}

// Fix Netscape 2.x Date bug
function fixDate(d) {
var a = d;
var b = new Date(0);
var s = b.getTime();
if (s > 0) a.setTime(a.getTime() - s);
return a;
}

function supportsCookies() {
setCookie('test', '1');
if (getCookie('test')) return true;
else return false;
}
function supportsCookie() {
var x ='<link rel="stylesheet" type="text/css" href="backtest.css" />';
if (!SupportsCookies);
return document.write(x);
}