[Current Forum ] [Archive 2003 - 2005]
[Register]  [Profile]  [Preferences]  [Search]
[Private messages]  [Memberslist]  [FAQ]  [Login]
Subsim Radio Room Forum Index » » Sub Command » » Need help with cookies
Author Need help with cookies
XabbaRus


Joined: Feb 28, 2002
Posts: 2792
Posted: 2003-01-09 06:40   
Hi guys,
I'm trying to build a cookie for my website.

Not having much luck. i go tmyself a decent book and also got some code of a javascript page which has a similar function and I'm trying to modify it.

The logic of my cookie goes like this.

IF user visits page for first time THEN play RadioSound

ELSE do not PLAY radiosound

End IF

IF updated news page THEN play RadioSound on visit

End IF


At the moment I'm just trying to get the first bit sorted out where once a user has heard the radiosound on subsequent visits he/she does not here it unless cookies are deleted or expired.

Later I want to be able to make it so that if I modify the news page the radiosound will play.

I've been looking at various scripts for example MadCowz script for his news window and I have a script that does that.

Here is the script I have and the mods I have made.


(SCRIPT LANGUAGE="JavaScript")

(!-- Begin
var expDays = 1; // number of days the cookie should last

var sound = "../Project971/sounds/radio00.wav";


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 DeleteCookie (name) {
var exp = new Date();
exp.setTime (exp.getTime() - 1);
var cval = GetCookie (name);
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
function amt(){
var count = GetCookie('count')
if(count == null) {
SetCookie('count','1')
return 1
}
else {
var newcount = parseInt(count) + 1;
DeleteCookie('count')
SetCookie('count',newcount,exp)
return count
}
}
function getCookieVal(offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}

function checkCount() {
var count = GetCookie('count');
if (count == null) {
count=1;
SetCookie('count', count, exp);

play.sound="../Project971/sounds/radio00.wav"

}
else {
count++;
SetCookie('count', count, exp);
}
}
// End -->
(/script)

[ This Message was edited by: XabbaRus on 2003-01-09 06:41 ]


  View Profile of XabbaRus   Goto the website of XabbaRus   ICQ status       Edit/Delete This Post   Reply with quote
XabbaRus


Joined: Feb 28, 2002
Posts: 2792
Posted: 2003-01-09 09:09   
bump, need help with this.

  View Profile of XabbaRus   Goto the website of XabbaRus   ICQ status       Edit/Delete This Post   Reply with quote
Monophonic


Joined: Feb 28, 2002
Posts: 279
From: Espoo, Finland
Posted: 2003-01-09 10:02   
Do your browsers current security settings allow scripts to access cookies? I usually turn that one off if it isn't already.
_________________
Signature unavailable during refit&resupply.


  View Profile of Monophonic   ICQ status         Edit/Delete This Post   Reply with quote
XabbaRus


Joined: Feb 28, 2002
Posts: 2792
Posted: 2003-01-09 16:18   
Oh yea, they work.
I'm just wanting someone to look at the code and help me understand it point out where I need to alter it to make it work.
_________________

Project 971


  View Profile of XabbaRus   Goto the website of XabbaRus   ICQ status       Edit/Delete This Post   Reply with quote
Lock this Topic Move this Topic Delete this Topic
Powered by phpBB Version 1.4.4
Copyright © 2000 - 2001 The phpBB Group

phpBB Created this page in 0.009052 seconds.