PDA

View Full Version : New user cookie - Do or do not?



Sliight
07-18-2007, 10:44 PM
I came upon a script that uses a cookie to tell if someone is new to my site or not. If they are new, it will redirect to an intro page. I like the idea of being able to have a direct message without letting them be distracted by the menus, or the slideshow. Basically I get their attention for 10 seconds, until they click the enter site button... I will paste the script at the end of the message for reference.

My question is this... Will this cause problems if the user has cookies set to off? Will it just constantly look for the cookie, not see it, and always send them back to the intro page? If that is the case, that would be super annoying and I wouldn't use the script. I'm hoping that if they have cookies off, it wouldn't redirect them, and would just let them sit on my home page.


Thank you!

Script:

Now here is the script. Just copy everything into your <head></head> tag. what you need to change is REDIRECTING LOCATION and COOKIE NAME (name this something unique that no one else will have)
<SCRIPT LANGUAGE="JavaScript">
<!-- Hide from old browsers


var caution = false

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" : "")
if (!caution || (name + "=" + escape(value)).length <= 4000)
document.cookie = curCookie
else
if (confirm("Cookie exceeds 4KB and will be cut!"))
document.cookie = curCookie
}

function getCookie(name) {
var prefix = name + "="
var cookieStartIndex = document.cookie.indexOf(prefix)
if (cookieStartIndex == -1)
return null
var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length)
if (cookieEndIndex == -1)
cookieEndIndex = document.cookie.length
return unescape(document.cookie.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)
}

var now = new Date()
fixDate(now)
now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000)
var visits = getCookie("newtousejeff")
if (!visits)
location = "http://www.usejeff.com/newuser.html"
setCookie("newtousejeff", visits, now)


// -->
</SCRIPT>

if you want the user to be able to see the entry page again, then they need to delete the cookie. Call this function from a link or a button. Using my example, it would look like this.
<form><input type="button" onClick="deleteCookie('COOKIE NAME'); location.reload();" value="Delete The Cookie"></form>

Twey
07-18-2007, 10:51 PM
My question is this... Will this cause problems if the user has cookies set to off? Will it just constantly look for the cookie, not see it, and always send them back to the intro page? If that is the case, that would be super annoying and I wouldn't use the script. I'm hoping that if they have cookies off, it wouldn't redirect them, and would just let them sit on my home page.It is the case, and yes, it would be annoying :)

Sliight
07-18-2007, 10:55 PM
Bummer...really looked like a cool idea to deliver the key message. Guess I'll have to rely on my keen eye and inherent intuitive design characteristics to be sure they get it.... er wait., who am I kidding!.. I can't draw, and I hang my paintings sideways. I guess instead I will go with the roll the dice theory and hope they get the message I'm trying to imply :)

Thanks Twey

Twey
07-18-2007, 10:57 PM
Intro pages are quite common, and not too bothersome if you remember to include a "skip intro" link somewhere easily accessible from the top. I'd think that combined with the cookie would be sufficient to justify its use.