Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

created page counter using javascript

Status
Not open for further replies.

thawatwong

Instructor
Aug 25, 2002
38
HK
Hi,any one can help?.I want to created a counteron my page
using javascript,but I don't know how can I make it work,please help.Thank
 
cookies are the only way for a client side counter
example from

Hit Counter
For those who just want to know how may times someone has visited the following code is all you need. This uses a single cookie called 'hitCount' that is incremented with every visit to a page.


// Original JavaScript code by Duncan Crombie: dcrombie at chirp.com.au
// Please acknowledge use of this code by including this header.

function greetVisitor() {
var hitCount = getCookie("hitCount");
if (hitCount == null) {
hitCount = 1;
document.write (&quot;<p>This is your first visit</p>&quot;);
} else {
document.write (&quot;<p>You have been here &quot; + (++hitCount) + &quot; times</p>&quot;);
}
setCookie(&quot;hitCount&quot;, hitCount);
}

To use this code you have to call the function from somewhere in the body of the page as shown below:


<SCRIPT language=&quot;JavaScript&quot;>

greetVisitor();

</SCRIPT>

admin@onpntwebdesigns.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top