April 26, 2005

Finally, A Fix for the Comment Remembering Problem

Fellow munuvians, here is a fix I implemented over at the Jawa. IT WORKS!!

For most mu.nu sites, for some reason, the cookies won't really work. So that your readers must fill in their information every time they want to comment. Gordon at Cranky Neocon took a gander at my site a few months back and fixed it.

Getting the cookies working is VITAL to readership growth. If you want to retain readers then make it easy for them to come back again and again to leave comments. Pretty soon you will have a real community of readers. And they tell their friends, and so on, and so on.

Anyway, here it is

UPDATE: This is as good as I could get it. Just e-mail me if you have problems removing the little smiley faces.

<em>In the section called <head> replace the existing <script></script> block with this code.</em>

<em><script type="text/javascript">
//<!--

var HOST = ''; //<$MTBlogHost$>';

// Copyright (c) 1996-1997 Athenia Associates.
// http://www.webreference.com/js/
// License is granted if and only if this entire
// copyright notice is included. By Tomer Shiran.

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

document.cookie = curCookie;
}

function getCookie (name) {
var prefix = name + '=';
var c = document.cookie;
var nullstring = '';
var cookieStartIndex = c.indexOf(prefix);
if (cookieStartIndex == -1)
return nullstring;
var cookieEndIndex = c.indexOf(";",
cookieStartIndex + prefix.length);
if (cookieEndIndex == -1)
cookieEndIndex = c.length;
return unescape(c.substring(cookieStartIndex + prefix.length, cookieEndIndex));
}

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

function fixDate (date) {
var base = new Date(0);
var skew = base.getTime();
if (skew > 0)
date.setTime(date.getTime() - skew);
}

function rememberMe (f) {
var now = new Date();
fixDate(now);
now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
setCookie('mpjauth', f.author.value, now, '', HOST, '');
setCookie('mpjmail', f.email.value, now, '', HOST, '');
setCookie('mpjhome', f.url.value, now, '', HOST, '');
}

function forgetMe (f) {
deleteCookie('mpjmail', '', HOST);
deleteCookie('mpjhome', '', HOST);
deleteCookie('mpjauth', '', HOST);
f.email.value = '';
f.author.value = '';
f.url.value = '';
}

//-->
</script>

At the bottom of the page put this code over the old code:
<script type="text/javascript">
//<!--
document.getElementById('email').value = getCookie("mpjmail");
document.getElementById('author').value = getCookie("mpjauth");
document.getElementById('url').value = getCookie("mpjhome");
if (getCookie("mpjauth")) {
document.getElementById('bakecookie').checked = true;
} else {
document.getElementById('forget').checked = true;
}
//-->
</script><html> </em>

Posted by Rusty at April 26, 2005 05:23 PM
Comments
#1

Rusty, you are such a tease. ;)

Posted by Tig at April 26, 2005 05:40 PM
#2

How do you get a script to show up in a post???

Posted by Rusty Shackleford at April 26, 2005 05:44 PM
#3

Fast easy way is to go to http://centricle.com/tools/html-entities/
Paste in your code, then hit 'encode'. Paste the results back into your post here.

Paul

(It' usually the angle brackets that trip you up. MT uses them to delineate code that should be executed, so it thinks your post is just yet another snippet of instructions for it to perform, as opposed to text to display.)

Posted by Light & Dark at April 26, 2005 06:09 PM
#4

Didn't work!

Posted by Rusty Shackleford at April 26, 2005 06:40 PM
#5

When I went to Centricle and put in my cookie script and hit encode, it worked. I'm going to post it on my site, Eric's Grumbles. Let me know if you need anything else.

Posted by Eric at April 26, 2005 07:16 PM
#6

Then replace the angle brackets with brackets or parentheses with instruction that the user will need to turn them back into angle brackets.

Posted by Tuning Spork at April 27, 2005 02:49 AM
#7

If you view the individual entry, the smilies disappear. Which is good in this case. :)

Posted by Pixy Misa at April 27, 2005 03:57 AM
#8

ok. Still not working for me. Am I a moron? I tried both Rusty's way and Eric's way. No dice. Help!

Posted by caltechgirl at April 27, 2005 04:19 AM
#9

Not sure what the issue is caltech, my method works great on my blog. At least it does for me and none of my regulars have grumbled about it. Since they let me know when 24 hours that I had hosed comments in general, I would expect one of them to have grumbled by now.

Posted by Eric at April 27, 2005 04:27 AM
#10

well never mind then. I tried it again and now it works. Don't ask me what I did differently. Thanks, guys.

Posted by caltechgirl at April 27, 2005 04:08 PM
#11

I just saw this. God bless you, Rusty.

Posted by Simon at May 9, 2005 07:44 AM
Live Comment Preview
Post a comment









Remember personal info?