开发者

Why doesn't this JQuery stylesheet switcher store a cookie?

I have a downloaded stylesheet switcher that doesn't seem to work properly.

The switcher works in as much as the new stylesheet is loaded, however the cookie that it is meant to store and read never actually occurs (I assume as much, as when I refresh the page it reverts back to the default stylesheet).

The console in chrome returns the following error:

Uncaught ReferenceError: readCookie is not defined

Now my theory was that the readCookie variab开发者_如何学Pythonle wasnt defined and i should move it to the top, but that just rendered the script completely inactive.

I'm not a complete newbie when it comes to jQuery, however this is a downloaded script and I've had no experience with javascript cookies before.

Any help would be HUGELY appreciated.

(function($)
{
  $(document).ready(function() {
    $('.styleswitch').click(function()
    {
      switchStylestyle(this.getAttribute("rel"));
      return false;
    });
    var c = readCookie('style');
    if (c) switchStylestyle(c);
  });

  function switchStylestyle(styleName)
  {
    $('link[@rel*=style][title]').each(function(i) 
    {
      this.disabled = true;
      if (this.getAttribute('title') == styleName) this.disabled = false;
    });
    createCookie('style', styleName, 365);
  }
})(jQuery);
// cookie functions http://www.quirksmode.org/js/cookies.html
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 var 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 eraseCookie(name)
{
  createCookie(name,"",-1);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜