scriptygoddess

22 Oct, 2003

Skinnable Comment Pop Ups

Posted by: Jennifer In: Script snippet

I did not write this code but I have been using it for a while. I have gotten quite a few emails about it and thought I would post it here to share with the masses. It's been working perfectly on my site for some time. This method can be used to skin your comment and trackback popups as well as any other pages that you link to your site. I also use it to skin my blogroll page.

Paste this code in between the head of your pop up page:

<script type="text/javascript" language="javascript">
function GetCookie(name) {
var startIndex = document.cookie.indexOf(name);
if (startIndex != -1) {
var endIndex = document.cookie.indexOf(";", startIndex);
if (endIndex == -1) endIndex = document.cookie.length;
return unescape(document.cookie.substring(startIndex+name.length+1, endIndex));
} else {
return null;
}} var style = GetCookie('skin');
if (style==null) {style=1;}
document.writeln("<link rel=\"stylesheet\" href=\"http://www.domainname.com/skins/css/styles-sheet" + style + ".css\" type=\"text/css\" />");
</script>

You will need to put all your css files in the same folder, and number them according to the corresponding skin #. Based on the script, you'll need to name your css files "styles-sheet#.css" for it to work. You can of course name them whatever you want if you change it in the script.

Also, by changing the # in this line:

if (style==null) {style=1;}

Will set the default skin number you want new visitors without a cookie set to see. It should correspond with whatever your default skin # is set to so it all matches.

I use this in conjunction with the skinning tutorial provided by Amy.

I originally posted it here on my site which is where you can find the original credits as well as a link to the MT Forum Thread that started the hoopla.

9 Responses to "Skinnable Comment Pop Ups"

1 | Queenie

October 23rd, 2003 at 11:04 am

Avatar

Ahh, it never occured to me to use javascript! On pages with a .php extension (like my tag board and index page) I've been using <link rel="stylesheet" href="http://whatever.com/skins/<?=$skin?>/style.css">, which has the advatage of working even if you have javascript turned off.

However, this method is great for search templates which have a .cgi extension and so don't use php. I've been looking for something like this, thankyou. :)

2 | Skybly

October 24th, 2003 at 3:05 am

Avatar

Here's another nifty method to skin non-php sites without javascript: synapse: skin your blog :)

3 | reb

January 25th, 2004 at 1:47 pm

Avatar

i'd really love to implement this, but the copy of mt that runs my blog site (where i'd like to use it) is actually on a different domain (with my blog as a subdomain of that domain). so when the comment pop-up pops up, it's actually a different domain then what the cookie for my my skins is set for. is there anyway you can get this to grab the cookies for a different domain listed? i know nothing about javascript, so you'll have to excuse me if this is a stupid question. :)

4 | Jennifer

January 25th, 2004 at 1:53 pm

Avatar

Unfortunately – you can only set a cookie for the domain you're on – and you can only read the cookie from the domain you're on – so you'd have to have two cookies – and set them each from the actualy domain itself. I wonder something like this would work: if on "domain a" – you set "cookie a" – and a script sends you to a page on "domain b" – which sets "cookie b" – and then this page sends you back again…

don't know if that makes sense – but that's what I would suggest.

5 | reb

January 27th, 2004 at 6:58 pm

Avatar

okay. :) thanks for the quick reply!

6 | Pixel Sphinx

November 2nd, 2003 at 4:48 pm

Avatar

Skinnable Comment Pop Ups
We have gotten a few emails from people about the skinnable comment pop ups. Boots tipped me off originally (thank…

7 | Thought Bubbles

September 6th, 2004 at 3:53 pm

Avatar

Under Construction…
OK I'm trying to add a skin..and that means I'm trying to get the skinning to work. Sooooooooo things will be REALLY wierd for a bit. Sit tight. I hope this works…. *UPDATE* Shoot me shoot me shoot me shoot…

8 | Tjej

September 10th, 2004 at 10:18 am

Avatar

There is an typo in there. A semi colon in the code that shouldn't be there. It's right after this:

<link rel="stylesheet" href="http://www.domainname.com/skins/css/styles-sheet"

.. and right before this:

+ style + ".css" type="text/css" />");

It was driving me mad when I was trying to use the code, it never worked. FINALLY my boyfriend pointed out the semicolon there, and then I took it out and it worked beautifully. :)

9 | Jennifer

September 10th, 2004 at 9:11 pm

Avatar

Thanks for the heads up. I've updated the post. :)

Featured Sponsors

Genesis Framework for WordPress

Advertise Here


  • Scott: Just moved changed the site URL as WP's installed in a subfolder. Cookie clearance worked for me. Thanks!
  • Stephen Lareau: Hi great blog thanks. Just thought I would add that it helps to put target = like this:1-800-555-1212 and
  • Cord Blomquist: Jennifer, you may want to check out tp2wp.com, a new service my company just launched that converts TypePad and Movable Type export files into WordPre

About


Advertisements