Closed Thread Icon

Preserved Topic: browser brain*?* Pages that link to <a href="https://ozoneasylum.com/backlink?for=17934" title="Pages that link to Preserved Topic: browser brain*?*" rel="nofollow" >Preserved Topic: browser brain*?*\

 
Author Thread
kars10
Bipolar (III) Inmate

From: Europe
Insane since: Mar 2001

posted posted 04-23-2001 23:02

My index page has an intro which looks loke a slide. Unfortunatly, I want the intro only when the user gets on it the first time. Until now, I had to upload a second index page and refer to that one. This is a lot of upgrading work and I wonder if there could be some kind of a memory way so that the intro-function gets blocked when it is loaded the second time. Cookies? php? I tried the cookies but it didn't work and I couldn;t do anything on php. :-\
Does Anyone know how?

k10

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 04-23-2001 23:36

I'd do it with cookies, but you said you tried it and it didn't work. Could you give us a link to the page so we can see what may not be working?

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 04-24-2001 06:57

Slime is right, you can do that only with cookies...

kars10
Bipolar (III) Inmate

From: Europe
Insane since: Mar 2001

posted posted 04-24-2001 23:48

ok, guys, I'll put that cookie in here. But later, HAve school right now!
(I don;t have all those cookie skillz anyway, hav an idea where I can learn some?)
k10

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 04-25-2001 02:10

Well, as you seem somewhat familiar with JavaScript, I'll give you a quick little tutorial...

document.cookie <- this is the object that contains and stores cookies.

Unlike most objects, you can't set it to a value and then read that value from it later. This is a weird object. When you set it to something, you're not really setting it to something. Instead, you're telling the browser to set a cookie. When you read from this object, you get a list of the cookies.

HOW TO SET A COOKIE

document.cookie = "name=value; expires=date; path=whatever_path_you_want; domain=whatever_domain_you_want; secure";

OK, I don't understand half of that myself. The important parts? name=value - that's simple. The name of your cookie (might be "HasSeenSplashScreen") and the value that it's set to (might be "true", "false", "yabbadabbadoo", or anything you want).

expires=date specifies the date after which the browser is allowed to delete the cookie. You can use the Date object for that. I'll give an example later.

path=something ... well, i'm not exactly sure what this does, even though I could look it up. The safest thing to do is say "path=/";

The other things i don't even understand, and it's safe to leave them out, so I just ignore them.

EXAMPLE OF SETTING A COOKIE

code:
function setCookie(name, value, expires)
{
if (!expires) expires = new Date(); // no expiration date specified? use this date and it will just be deleted soon.
document.cookie = name + "=" + escape(value) + "; expires=" + expires.toGMTString() + "; path=/";
}

var expdate = new Date (); // pre-set to the current time and date
expdate.setTime(expdate.getTime() + 1000 * 60 * 60 * 24 * 365); // add one year to it
//365 days/year * 24 hours/day * 60 minutes/hour * 60 seconds/minute * 1000 milliseconds/second
// = howevermany milliseconds/year. So this adds one year, it'll expire in one year.
setCookie("skipSplash","true",expdate);



Note the use of the escape() function, which sort of encodes the cookie's value so that you don't have to worry about weird characters in it, which could mess stuff up. We unencode it later.

HOW TO READ PREVIOUSLY SET COOKIES

This is easier. When you read from document.cookie, you get a bunch of "name=value;" pairs. The expiration dates and all that junk aren't specified, you don't really need to know it anyway. The tricky part is when you have a lot of cookies, it can look like "myname=John;yourname=kars10;mypet=dog;yourpet=rodent;" it can get tough to pick out a specific cookie. Here's a function that will do it.

EXAMPLE OF READING A PREVIOUSLY SET COOKIE

code:
function getCookie(name)
{
var cookies = document.cookie;
if (cookies.indexOf(name) != -1)
{
var startpos = cookies.indexOf(name)+name.length+1;
var endpos = cookies.indexOf(";",startpos)-1;
if (endpos == -2) endpos = cookies.length;
return unescape(cookies.substring(startpos,endpos));
}
else
{
return false; // the cookie couldn't be found! it was never set before, or it expired.
}
}



That uses some fancy string manipulation to extract the value of the cookie and unencode it.

Just a couple things to keep in mind: the browser doesn't have to store more than 300 cookies total from anywhere on the internet, no more than 20 from your server, and no more than 4 kilobytes per cookie, counting both name and value.

You can't get a cookie set at another site, nor can another site get at your cookie.

Hope that helps, any questions, please ask - I may have been confusing. =)

- Slime

mobrul
Bipolar (III) Inmate

From:
Insane since: Aug 2000

posted posted 04-25-2001 04:12

Before I read this post I had absolutely no interest in cookies...I never had any reason to use them.
You have provided a well written catalyst to my further exploration.
Off to find out what path and domain do.

Thanks.

BTW, Slime, when is the long version going to appear over at GURU's NETWORK.....?

mobrul

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 04-25-2001 07:13

JavaScript library for cookie manipulating can be found here: http://www.claws-and-paws.com/software/nibbler/index.shtml

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 04-25-2001 15:33

Heh, I was thinking as I wrote that that it would make a good tutorial. Maybe I'll write that...

problem with GN is that you have to do so much stuff aside from just writing, get it to work in the template and all, submit it, sort of a nuisance. eh.

kars10
Bipolar (III) Inmate

From: Europe
Insane since: Mar 2001

posted posted 04-26-2001 01:51

I still didn't find my cookie but I didn't want to stand in here as a square.
I read something interesting about cookies and there safety...
Anyway, there is that cookie from doubleclick.net and if it is not on your Computer already you belon to 2 out of 10!
This cookie stores all kinds of stuff especially where you surfed and so on. THat information is send forward to sellers (who of course pay big bugs for that!).
Even without never being on doubleclick. net you can actually have it on your hard drive. "No way!" is what I said until I went through my cookies and I found it...
Just wanted you to know that...
I another side of cookies
k10

kars10
Bipolar (III) Inmate

From: Europe
Insane since: Mar 2001

posted posted 04-26-2001 01:57

I found the page from where I got my old cookie from: That is it, I want to recommend it since it distinguishs between browsers AND platforms. (Unfortunaly not uptodate since "WIN2000" and "WinME" are missing)
I want to thank slime, I'll check that out.
here it is:

**********************************************************************

<!-- Hide this script from old browsers --
var whichVersion = navigator.appVersion;
var platform = "";
var netscapev = "";
var i = 1;
if (whichVersion.substring(0,3) == "2.0") {netscapev="2"}
else if (whichVersion.substring(0,3) == "3.0") {netscapev="3"}
else {netscapev="1"}


while (i < whichVersion.length)
{
if (whichVersion.substring(i,i+1) == "(")
{
if (whichVersion.substring(i+1,i+4) == "Mac") {platform="Mac";}
else if (whichVersion.substring(i+1,i+6) == "Win16") {platform="Win";}
else if (whichVersion.substring(i+1,i+6) == "Win95") {platform="Win95";}
else if (whichVersion.substring(i+1,i+6) == "WinNT") {platform="WinNT";}
else {platform = "UNIX";}
break;
}
i = i + 1;

}

function getCookieVal (offset)
{
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1){endstr = document.cookie.length;}
return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name)
{
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen)
{
var j = i + alen;
if (document.cookie.substring(i, j) == arg){return getCookieVal (j);}
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) {break;}
}
return null;
}

function SetCookie (name, value)
{
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}

function setLastHereOnCookie ()
{
var rightNow = new Date()
var expdate = new Date()
expdate.setTime (expdate.getTime() + 60*(24 * 60 * 60 * 1000)) // dead in 2 months
SetCookie ("lastHereOn", rightNow.getTime(), expdate, "/")
}

var lastVisit = GetCookie("lastHereOn")
var htm = '<table width=10 cellspacing=0 cellpadding=2 border=0><tr><td valign=top rowspan=4 width=200></a></td>'
Src='<tr><td width=300><br></td></tr><td width=10></td></tr><tr><td width=300><table width=300 cellspacing=0 cellpadding=3 border=0><tr><td width=1></td><td width=299>';

if (platform == "Win95" && netscapev=="2") {htm += Src +"Netscape 2.0 and Windows 95";}
else if (platform == "Win95" && netscapev=="3") {htm += Src +"Netscape 3.0 and Windows 95";}
else if (platform == "Mac" && netscapev=="2") {htm += Src +"Netscape 2.0 and Macintosh";}
else if (platform == "Mac" && netscapev=="3") {htm += Src +"Netscape 3.0 and Macintosh";}
else if (platform == "WinNT" && netscapev=="2") {htm += Src +"Netscape 2.0 and Windows NT";}
else if (platform == "WinNT" && netscapev=="3") {htm += Src +"Netscape 3.0 and Windows NT";}
else if (platform == "UNIX" && netscapev=="2") {htm += Src +"Netscape 2.0 and UNIX";}
else if (platform == "UNIX" && netscapev=="3") {htm += Src +"Netscape 2.0 and UNIX";}
else if (platform == "Win" && netscapev=="2") {htm += Src +"Netscape 2.0 and Windows 3.1";}
else if (platform == "Win" && netscapev=="3") {htm += Src +"Netscape 3.0 and Windows 3.1";}
else {htm += Src;}

htm += "</td></tr><tr><td width=1></td><td width=299>";

if (lastVisit == null) {htm += "No record of you visiting in the last 2 months."}
else
{
var exp = 960201
var proc = 960001
var nut = 960001
var news = 960401
var sand = 960401
var soap = 960401
// mac getTime() but workaround, when they fix it this will be wrong...be vigilant
if (platform == "Mac") {
lastVisit = lastVisit - (24 * 60 * 60 * 1000) // getTime() one day off on Mac;
}
htm += "Since you last visited on<br><b>"
lastVisit = 1 * lastVisit // integerize that stringy cookie
var lastHereFormatting = new Date(lastVisit); // Date-i-fy that number
var intLastVisit = (lastHereFormatting.getYear() * 10000)+(lastHereFormatting.getMonth() * 100) + lastHereFormatting.getDate()
var lastHereInDateFormat = "" + lastHereFormatting; // Gotta use substring functions
var dayOfWeek = lastHereInDateFormat.substring(0,3)
var dateMonth = lastHereInDateFormat.substring(4,11)
var timeOfDay = lastHereInDateFormat.substring(11,16)
var year = lastHereInDateFormat.substring(23,25)
htm += dayOfWeek + ", " + dateMonth + " at " + timeOfDay // display
htm += "</b>,"
var noChange=0
if (intLastVisit < exp) {noChange = 1; Src = '<a href="cookie2.htm">Java</a> section has been updated'; htm += "<br>Our " + Src}
if (intLastVisit < proc) {noChange = 1;Src = '<a href="cookie.html">Cookie</a> section has been updated'; htm += "<br>Our " + Src}
if (intLastVisit < nut) {noChange = 1; Src = '<a href="files.htm">Software</a> section has been updated'; htm += "<br>Our " + Src}
if (intLastVisit < sand) {noChange = 1; Src = '<a href="faq.htm">Cookie FAQ</a> section has been updated'; htm += "<br>Our " + Src}
if (intLastVisit < soap) {noChange = 1; Src = '<a href="extcookie.htm">Shopping Cart</a> section has been updated'; htm += "<br>Our " + Src}
if (intLastVisit < news) {noChange = 1; Src = '<a href="value.htm">Cookie Values</a> section has been updated';htm += "<br>Our " + Src}
if (noChange == 0) {htm += "<br>there has been some updates ... enjoy"}
}

setLastHereOnCookie()
htm += "</td></tr><tr><td width=1></td><td width=299>"
Src = '</td></tr>'
htm += Src + "</table></tr></table>";
document.write(htm)

// -- End Hiding Here -->

*forgotubbcoding****************************************************

this cookie tells you the day and the time you were last on the page.
(I think that htm-idea which grows through the script and than gets written out in that document.write is genial. This stuff and the cookies opens doors!)
k10
keep on typin'

DocOzone
Maniac (V) Lord Mad Scientist
Sovereign of all the lands Ozone and just beyond that little green line over there...

From: Stockholm, Sweden
Insane since: Mar 1994

posted posted 04-26-2001 10:16

Great summary! Slime, you already have all the text for the tutorial right here in your post, don't you? I think one of the best way to compile some of your cooler tutes would be to collect them all in a "Hey Slime! How do you... ?" archive. You could collect a list of questions, and then make pretty versions of your posts, leaving all the chatty bits included, it would work, and work well.

(This thread was archived to the FAQ section. Mad Scientists, this seems like a good idea, feel free to archive them to the FAQ section, leaving them in place if you see something just *way* useful anc concise in a post.)

Your pal, -doc-

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 04-26-2001 16:54

Cool idea, Doc, that could be neat.

Oh, that doubleclick.net cookie, you know how you get that? even if you haven't been to doubleclick.net, a *ton* of banner ads are actually IFrames that link to it, or go to it in some other way, or you go through it when you click them. That's when the cookie is set.

« BackwardsOnwards »

Show Forum Drop Down Menu