PDA

View Full Version : Number of Visits


Matt001
11-02-2003, 12:21 PM
I found a number of visits script on a website and i would like it if someone could help me with it.
I need it to display different things when the number of visits have gone up.
So when they have visited the page 100 times a message appears saying something.
Heres the code.


<script language="Javascript">
<!--
// please keep these lines on when you copy the source
// made by: Nicolas - http://www.javascript-page.com

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 DeleteCookie(name) {
var exp = new Date();
FixCookieDate (exp); // Correct for Mac bug
exp.setTime (exp.getTime() - 1); // This cookie is history
var cval = GetCookie (name);
if (cval != null)
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

var expdate = new Date();
var num_visits;
expdate.setTime(expdate.getTime() + (5*24*60*60*1000));
if (!(num_visits = GetCookie("num_visits")))
num_visits = 0;
num_visits++;
SetCookie("num_visits",num_visits,expdate);
//-->
</script>

<script language="Javascript">
<!--
// please keep these lines on when you copy the source
// made by: Nicolas - http://www.geocities.com/ResearchTriangle/1500

document.write("You have been to this page "+num_visits+" times.");
//-->

</script>

piglet
11-02-2003, 12:36 PM
Hi,

Maybe I'm missing your point...but here goes:


<script language="Javascript">
<!--
// please keep these lines on when you copy the source
// made by: Nicolas - http://www.geocities.com/ResearchTriangle/1500
if (num_visits>99)
document.write("You have been to this page "+num_visits+" times.");
//-->
</script>


for "document.write(blah)" substitute whatever you want to happen.

Matt001
11-02-2003, 12:46 PM
thx piglet.
I was doing the same process as you but i didnt know where to put ( and ) or even if i should put () in it.
Thx for the simple if value = then document.write script.
Im learning about java script and i can modify java for my own use but i dont know much when it comes to creating java script script from scratch.

Matt001
11-02-2003, 01:07 PM
Piglet can you help me with displaying something from a certain amount of visits.

So if a person visits the page between 10 and 20 times it displays the same text and then when its 21 visits it displays something else.

piglet
11-03-2003, 07:43 AM
Sure...

You can just test the number and do some action or other if the test returns true...

if (num_visits>30)
document.write("You have been to this page more than 30 times.");
else if (num_visits>20)
document.write("You have been to this page more than 20 times.");
else if (num_visits>10)
document.write("You have been to this page more than 10 times.");