JavaScript DHTML/Page Components/Counter

Материал из Web эксперт
Перейти к: навигация, поиск

A Personal Web Page Access Counter

   <source lang="html4strict">

/* Mastering JavaScript, Premium Edition by James Jaworski ISBN:078212819X Publisher Sybex CopyRight 2001

  • /

<HTML> <HEAD> <TITLE>Keeping track of Web page access</TITLE> <SCRIPT LANGUAGE="JavaScript"></SCRIPT> </HEAD> <BODY BGCOLOR="#FFFFFF"> <SCRIPT LANGUAGE="JavaScript"></SCRIPT>

Keeping track of Web page access

</body> </HTML>

      </source>
   
  


Counter with images

   <source lang="html4strict">

//Bogus Counter script - http://www.btinternet.ru/~kurt.grigg/javascript /* 1: Make sure the counter images are in a folder/directory called exactly

  "counterdigits". Make sure this folder is in the same folder as the web page 
  using the script.
  

2: Put this js link between the head tags of your page html.

  Make sure the counter.js file is in the web page folder, NOT the images folder.
 <script type="text/javascript" src="counter.js"></script>

3: Copy and paste this div html to where ever you want the counter to appear in the

  page. Other divs and tables etc OK.

4: To alter the counter length and start value, right click on the counter.js file

  and choose edit.
  • /

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>Bogus Counter</title> <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"> <meta http-equiv="content-language" content="en"> <meta http-equiv="content-script-type" content="text/javascript"> <meta http-equiv="content-style-type" content="text/css"> <style type="text/css"> body{ background-color : #000000; } </style>

<script type="text/javascript"> //Bogus Counter script - http://www.btinternet.ru/~kurt.grigg/javascript if ((document.getElementById && document.createElement("img")) && window.addEventListener || window.attachEvent){ (function(){ //Customize the counter here. //How many digits do you want in your counter? var counter_length = 7; //Choose a start value. If your "counter_length" is 7, "counter_start_from" MUST be 7 numbers long! var counter_start_from = "9999980"; //Gives a random hit anywhere from 0 to "random_timer" seconds. var random_timer = 2;

//Nothing needs altering past here! var pics = []; var load = []; for(i = 0; i < 10; i++){

pics[i]=i+".gif";

} for(i = 0; i < pics.length; i++){

load[i] = new Image();
load[i].src = "counterdigits/"+pics[i];

} var temp_stop = []; var stop; var c = ""; for(i = 0; i < counter_length; i++){ temp_stop[i] = 9; stop = c+=temp_stop[i]; } var counter_end_at = parseInt(stop); if (counter_start_from.length != counter_length){ alert("You want the counter to be "+counter_length+" digits long.\nThe variable \"counter_start_from\" must be "+counter_length+" digits long too!\nYou have it set to "+counter_start_from.length+"."); return false; } //Stop Opera selecting anything whilst dragging! Not ideal, keep eye on this for future version probs. if (window.opera){ document.write("<input type="hidden" id="Q" value=" ">"); } var y,x,z,temp1,temp2,dom,temp3,temp4; var n = 500; var dragOK = false; var timer = 1000; random_timer *= 1000; var disp = [];

document.write("