PDA

View Full Version : Help with cookies!!


Wobbler
09-30-2002, 02:17 PM
I know this isn't the right place to write but i couldn't find the right one so I test here!

How do I do a cookie that works like this!

1) When you enter the index.htm page a splash image will be shown, and under the image there is a box.
When you check that box it will save a cookie that makes when you you visit the site next time you will enter index2.htm page directly instead to click the splash image at the index.htm page!!

Wobbler
09-30-2002, 07:46 PM
someone must know how to do this!!

Wobbler
09-30-2002, 08:55 PM
This is the code I use:


<form action="index2.htm" method="POST">
<input type=hidden name=goupdates value="TRUE">
<input type=checkbox name=dummy onmouseup="javascript:document.forms[0].submit();" value="ON" style="position: relative; top: 2; font-family: Verdana; font-size: 8pt"><font face="Verdana" size="1">Check
this box if you want to get to the main site directly the next time you
visit.</font>
</form>


How do i make it work with cookies!!!!!! Som1 please help! I beg you

RadarBob
09-30-2002, 09:53 PM
The first page saves a cookie
When the checkbox is checked a function is triggered that saves the specific URL into a cookie.

The second page looks for the cookie
The second page needs to look for the cookie to see if it exists. If so, grab the URL and go there. If the cookie doesn't exist do whatever - stay here?

Go to the URL
That should be as simple as a one liner to change the window.location property.

by the way
You're gonna have to come up with / find the code for getting and storing the cookie. I'm not gonna write it here. It's nothing more than string manipulation. Remember that a cookie is literally this: CookieName=CookieValue;. Thats "a name", "an equal sign", "a value", and "a semicolon".

You're gonna want to put all the cookie making utility code into a file and "include" it on the page you use it.

You'll need to set the cookie "expires" attribute or else it will automatically go away when the session ends.

I'm not sure about this...
How to reference a cookie from a page that didn't create it.

If you set the cookie "path" attribute to "/" (ie 'root of my web site') then any web page in or under this subdirectory can access that cookie. I assume you just reference it by it's name, i.e. no object-dot notation to tell where it comes from.


Code On the first page:

<script type="text/javascript" src="/subdirectory/cookieCode.js"></script>
. . .

function BuildAutoGoToURL (theChkBox) {
if (theChkBox.checked == false) {
deleteCookie ("theMainPage");
}else {
makeCookie ("theMainPage", "http://www.ronco.com");
}
}

</script>
</head>

<body>
. . .
<input type="checkbox" value="" onclick="BuildAutoGoToURL(this)">
From now on go directly to the main page

. . .
</body>

Code On the second page:

<script type="text/javascript" src="/subdirectory/cookieCode.js"></script>
. . .

function AutoGoToURL () {
var goHere = null;

goHere = getCookie ("theMainPage");

if (goHere != null) {
window.location = goHere;
}else{
continue;
}
}

</script>
</head>
. . .
<body onload="AutoGoToURL();">
. . .
</body>