For part of my degree course i have to design a website. We are marked mainly on the ideas and set up of the site, not really on how it looks. They way it starts is a person will go to the site and first go to the intro page which will mainly be a short flash animation.
What i would like to include is soma kind of code that places a cookie in the personas computer when they first visit the site, then when the person returns to the site i want it so there is some kind of code in my intro page that checks for that cookie, if the cookie is there then it redirects it to the 'main' page rather than loading the intro page up again.
I'm guessing the best or only way to achieve this would be through the use of a cookie and using javascript, so i was wondering...
1) is this even possible?
2) could someone either point me in the direction to were i can get the code or info i need to do this or even provide me with the code i need? I tried google but didn't get much luck, wasn't sure what i was even looking for or if what i wanted to do was possible
3) any other ideas of demonstrating the use of javascript is welcome
Thanks alot
Cookies/JavaScript
Moderators: Moderators, Junior Moderators
- YoUnG_Bl0o0d
- Posts: 131
- Joined: Fri Oct 22, 2004 6:49 am
- Location: Birmingham
yes its possible a good resource for all Javascrip issues is located at their website, the actuall code you want is located her
http://javascript.internet.com/cookies/ ... irect.html
dont just cut and paste the code's, make sure you spend a few minutes reading through it, have fun sxb
http://javascript.internet.com/cookies/ ... irect.html
dont just cut and paste the code's, make sure you spend a few minutes reading through it, have fun sxb
- YoUnG_Bl0o0d
- Posts: 131
- Joined: Fri Oct 22, 2004 6:49 am
- Location: Birmingham
Smooth i re-wrote the code's myself but still after hours of carefully going through them i still cant get it to work, her it is
function ReDirect (URL) {
GetCookie('SplashSkip');
if (Splash == 'TRUE') {
window.location=(URL);
}
else {}
}
var Splash = GetCookie('SplashSkip');
</head>
<body>
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;
}
ReDirect('mainpage.htm);
function SetCookie (name, value) {
// Enter number of days the cookie should persist
var expDays = 30;
var exp = new Date();
exp.setTime(exp.getTime() + (expDays * 24 * 60 * 60 * 1000));
expirationDate = exp.toGMTString();
// Set cookie with name and value provided
// in function call and date from above
document.cookie = name + '=' + escape(value)
document.cookie += '; expires=' + exp.toGMTString();
}
//--> this is LINE 53!!!
// -->
</script>
<body onload="SetCookie('SplashSkip','TRUE');">
<div align="center"><a href="pop.htm">this is a link</a></div>
</body>
</html>
all i know is there is an error on line 53 why i have said in the code line number 53 is to save you counting, in actual fact i left it blank. From what i can gather it is expecting an object to be on that line, most likley my flash animation? i was wondering if that was the reason why it wasn't working right now because i havn't inserted the flash object into the site yet? could that be the case.? i'm struggling could any 1 help
function ReDirect (URL) {
GetCookie('SplashSkip');
if (Splash == 'TRUE') {
window.location=(URL);
}
else {}
}
var Splash = GetCookie('SplashSkip');
</head>
<body>
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;
}
ReDirect('mainpage.htm);
function SetCookie (name, value) {
// Enter number of days the cookie should persist
var expDays = 30;
var exp = new Date();
exp.setTime(exp.getTime() + (expDays * 24 * 60 * 60 * 1000));
expirationDate = exp.toGMTString();
// Set cookie with name and value provided
// in function call and date from above
document.cookie = name + '=' + escape(value)
document.cookie += '; expires=' + exp.toGMTString();
}
//--> this is LINE 53!!!
// -->
</script>
<body onload="SetCookie('SplashSkip','TRUE');">
<div align="center"><a href="pop.htm">this is a link</a></div>
</body>
</html>
all i know is there is an error on line 53 why i have said in the code line number 53 is to save you counting, in actual fact i left it blank. From what i can gather it is expecting an object to be on that line, most likley my flash animation? i was wondering if that was the reason why it wasn't working right now because i havn't inserted the flash object into the site yet? could that be the case.? i'm struggling could any 1 help
Young.
The major problem you got is that you dont understand the debug process
The debug is showing where the script engine found the error line 53. When the script is ran in blank lines they are not processed therefore in your code line 53 its actualy the line above, It can sometimes be hard to find an error expecially if you dont understand the debug process, her is the exact code you should have had
<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
function ReDirect (URL) {
GetCookie('SplashSkip');
if (Splash == 'TRUE') {
window.location=(URL);
}
else {}
}
var Splash = GetCookie('SplashSkip');
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;
}
ReDirect(INESERT THE URL TO THE PAGE you WANT TO REDIRECT TO HERE);
function SetCookie (name, value) {
// Enter number of days the cookie should persist
var expDays = 30;
var exp = new Date();
exp.setTime(exp.getTime() + (expDays * 24 * 60 * 60 * 1000));
expirationDate = exp.toGMTString();
// Set cookie with name and value provided
// in function call and date from above
document.cookie = name + '=' + escape(value)
document.cookie += '; expires=' + exp.toGMTString();
}
// -->
</script>
<body onload="SetCookie('SplashSkip','TRUE');">
</head>
<body>
Insert your body here
</body>
</html>
The major problem you got is that you dont understand the debug process
The debug is showing where the script engine found the error line 53. When the script is ran in blank lines they are not processed therefore in your code line 53 its actualy the line above, It can sometimes be hard to find an error expecially if you dont understand the debug process, her is the exact code you should have had
<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
function ReDirect (URL) {
GetCookie('SplashSkip');
if (Splash == 'TRUE') {
window.location=(URL);
}
else {}
}
var Splash = GetCookie('SplashSkip');
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;
}
ReDirect(INESERT THE URL TO THE PAGE you WANT TO REDIRECT TO HERE);
function SetCookie (name, value) {
// Enter number of days the cookie should persist
var expDays = 30;
var exp = new Date();
exp.setTime(exp.getTime() + (expDays * 24 * 60 * 60 * 1000));
expirationDate = exp.toGMTString();
// Set cookie with name and value provided
// in function call and date from above
document.cookie = name + '=' + escape(value)
document.cookie += '; expires=' + exp.toGMTString();
}
// -->
</script>
<body onload="SetCookie('SplashSkip','TRUE');">
</head>
<body>
Insert your body here
</body>
</html>
-
- Similar Topics
- Replies
- Views
- Last post
-
- 6 Replies
- 950 Views
-
Last post by Twist
-
- 5 Replies
- 493 Views
-
Last post by idol
-
- 2 Replies
- 294 Views
-
Last post by R.I.P Kiyan
-
- 15 Replies
- 941 Views
-
Last post by Cheroke
-
- 3 Replies
- 614 Views
-
Last post by quark
-
- 5 Replies
- 496 Views
-
Last post by Amirsade
-
- 31 Replies
- 1826 Views
-
Last post by precious_dyme
-
- 3 Replies
- 9025 Views
-
Last post by supriyala
-
- 4 Replies
- 1424 Views
-
Last post by afisoone
-
- 2 Replies
- 937 Views
-
Last post by Turbulence