Forum Moderators: open

Message Too Old, No Replies

Firefox JS does not work with WWW

Everything else works fine...

         

JAB Creations

1:07 am on Feb 11, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This script does not work when accessed in Firefox with www in the url but it works fine in all other situations. Any ideas?

//<![CDATA[
var $theme = getCookie("theme"); function getCookie(Name) { var search = Name + "="; var CookieString = document.cookie; var result = null;
if (CookieString.length > 0) { offset = CookieString.indexOf(search); if (offset!= -1) { offset += search.length; end = CookieString.indexOf(";", offset)
if (end == -1) {end = CookieString.length}; result = unescape(CookieString.substring(offset, end))}}return result;}

if ($theme == null)
{
if (document.getElementById) {
var l=document.createElementNS("http://www.w3.org/1999/xhtml","link");
l.setAttribute("href", "http://www.example.com/themes/theme-city.css");
l.setAttribute("media", "screen");
l.setAttribute("rel", "stylesheet");
l.setAttribute("title", "city");
l.setAttribute("type", "text/css");
document.getElementsByTagName("head")[0].appendChild(l);
}
}

else if ($theme == "city")
{
if (document.getElementById) {
var l=document.createElementNS("http://www.w3.org/1999/xhtml","link");
l.setAttribute("href", "http://www.example.com/themes/theme-city.css");
l.setAttribute("media", "screen");
l.setAttribute("rel", "stylesheet");
l.setAttribute("title", "city");
l.setAttribute("type", "text/css");
document.getElementsByTagName("head")[0].appendChild(l);
}
}

else if ($theme == "classic")
{
if (document.getElementById) {
var l=document.createElementNS("http://www.w3.org/1999/xhtml","link");
l.setAttribute("href", "http://www.example.com/themes/theme-classic.css");
l.setAttribute("media", "screen");
l.setAttribute("rel", "stylesheet");
l.setAttribute("title", "classic");
l.setAttribute("type", "text/css");
document.getElementsByTagName("head")[0].appendChild(l);
}
}

else if ($theme == "emerald")
{
if (document.getElementById) {
var l=document.createElementNS("http://www.w3.org/1999/xhtml","link");
l.setAttribute("href", "http://www.example.com/themes/theme-emerald.css");
l.setAttribute("media", "screen");
l.setAttribute("rel", "stylesheet");
l.setAttribute("title", "emerald");
l.setAttribute("type", "text/css");
document.getElementsByTagName("head")[0].appendChild(l);
}
}
//]]>

John

Bernard Marx

2:38 pm on Feb 11, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



We need some debug info, John.

Considering that the script seems to depend on the subdomain, I'd put all my money on this being a cookie path problem (not my speciality, I'm afraid). The page doesn't have access to the cookie at all.

You have attempted to allow for this with: if ($theme == null)...

You cookie script will (I think) return an empty string, of there's no cookie, but remember that, in Javascript:

[b]"" [red]!=[/red] null[/b]