Twilight92
06-03-2006, 03:49 PM
I wanted a script where the user veiws the page once and might see a link that says, "Continue". But the second time the user veiws the page, the text will change to something like, "Sorry you may only access this page once per day. Please return tommorow." The next day the text will reset and read, "continue" again.
I went to another forum and asked the same questions and helpfully they returned a few scripts.
The first of which will work in my situation quite fine although it isn't exactly what I wanted. In this script, you press the link 'Try this' for the first time and an alert box pops up and says, "Sorry, but you can only visit this page once a day. Try again tomorrow." and that's what it always has done.
Here it is:
<html>
<head>
<title>Demo Box</title>
<script language="javascript">
function ConfirmChoice()
{
answer = alert("Sorry, but you can only visit this page once a day. Try again tomorrow.")
if (answer !=0)
{
location = "index.html"
}
}
</script>
</head>
<body>
<div align="center"><a href="#" onclick=" ConfirmChoice(); return false;">Try this!!! </a> </div>
</body>
</html>
The second of the scripts I do not have the knowledge or ability to describe in detail the problems, although I do know that it does not work.... but maybe you know more about how it works and what the problem is. Usually, when I insert the correct pages into the script, it always goes to the page that the user is only supposed to see once a day.
Here it is:
<SCRIPT LANGUAGE="JavaScript">
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 = (2 < argc) ? argv[2] : null;
var path = (3 < argc) ? argv[3] : null;
var domain = (4 < argc) ? argv[4] : null;
var secure = (5 < argc) ? 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 DisplayInfo() {
var expdate = new Date();
var visit;
expdate.setTime(expdate.getTime() + (24));
if(!(visit = GetCookie("visit")))
visit = 0;
visit++;
SetCookie("visit", visit, expdate, "/", null, false);
var message;
if(visit == 1)
alert("Welcome!")
if(visit>= 2)
alert("You've been here too many times. Try again tommorrow.")
window.location="about:home"
}
function ResetCounts() {
var expdate = new Date();
expdate.setTime(expdate.getTime() + (24 * 60 * 60 * 1000 * 365));
visit = 0;
SetCookie("visit", visit, expdate , "/", null, false);
history.go(0);
}
window.onload=DisplayInfo
</Script>
Please keep in mind that I am the very most basic kind of begineer there is to Javascripts (I only got Javascript for dummies yesturday) so I can't edit these scripts myself (thus my post, here at CodingFurums).
Let's say to keep things organized, we will refer to the too existing problem scripts as script 1 and script 2.
Also, because of the way my page is set up, users will not be able to refresh the page that the once a day access script will be on.
Furthermore, any completely new scripts and script ideas are completely welcome. :D
Thanks in advance!
I went to another forum and asked the same questions and helpfully they returned a few scripts.
The first of which will work in my situation quite fine although it isn't exactly what I wanted. In this script, you press the link 'Try this' for the first time and an alert box pops up and says, "Sorry, but you can only visit this page once a day. Try again tomorrow." and that's what it always has done.
Here it is:
<html>
<head>
<title>Demo Box</title>
<script language="javascript">
function ConfirmChoice()
{
answer = alert("Sorry, but you can only visit this page once a day. Try again tomorrow.")
if (answer !=0)
{
location = "index.html"
}
}
</script>
</head>
<body>
<div align="center"><a href="#" onclick=" ConfirmChoice(); return false;">Try this!!! </a> </div>
</body>
</html>
The second of the scripts I do not have the knowledge or ability to describe in detail the problems, although I do know that it does not work.... but maybe you know more about how it works and what the problem is. Usually, when I insert the correct pages into the script, it always goes to the page that the user is only supposed to see once a day.
Here it is:
<SCRIPT LANGUAGE="JavaScript">
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 = (2 < argc) ? argv[2] : null;
var path = (3 < argc) ? argv[3] : null;
var domain = (4 < argc) ? argv[4] : null;
var secure = (5 < argc) ? 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 DisplayInfo() {
var expdate = new Date();
var visit;
expdate.setTime(expdate.getTime() + (24));
if(!(visit = GetCookie("visit")))
visit = 0;
visit++;
SetCookie("visit", visit, expdate, "/", null, false);
var message;
if(visit == 1)
alert("Welcome!")
if(visit>= 2)
alert("You've been here too many times. Try again tommorrow.")
window.location="about:home"
}
function ResetCounts() {
var expdate = new Date();
expdate.setTime(expdate.getTime() + (24 * 60 * 60 * 1000 * 365));
visit = 0;
SetCookie("visit", visit, expdate , "/", null, false);
history.go(0);
}
window.onload=DisplayInfo
</Script>
Please keep in mind that I am the very most basic kind of begineer there is to Javascripts (I only got Javascript for dummies yesturday) so I can't edit these scripts myself (thus my post, here at CodingFurums).
Let's say to keep things organized, we will refer to the too existing problem scripts as script 1 and script 2.
Also, because of the way my page is set up, users will not be able to refresh the page that the once a day access script will be on.
Furthermore, any completely new scripts and script ideas are completely welcome. :D
Thanks in advance!