1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

web hit counter

Discussion in 'Software' started by parsley, Jun 20, 2003.

  1. parsley

    parsley Private E-2


    This may be a stupid question, but it is possible to create a webpage that has a real time hit counter, that does not need the client side browser to hit refresh to have the hit counter update.
    For example, we want to have it show the changes in a steady stream to the client without them needing to refresh?

    Thanks very much!
  2. da chicken

    da chicken MajorGeek

    Without creating an applet to do it, I don't think so. The hit counter is generally a server-side object. The client can't access it without requesting data from the server, so I don't see anyway to make JavaScript do it.

    The easiest method off the top of my head would be to write a Java applet that would open a connection to your server and receive updates. That wouldn't be a very efficient task, though.
  3. ChViRuS

    ChViRuS Private E-2

    it's possible. Just not over the HTTP layer. It is possible to write a remote agent in something like Java, which downloaded to the client's machine and did the required functions. Either that, or you could insert a refresh META command to refresh, eg a frame... but that's not what you want. It's not easy, and not possible in JS, HTML or a backend language.

    PS - this would have been better in the "programming" section.
  4. da chicken

    da chicken MajorGeek

    I think ChViRuS is on to something.

    Ok, use javascript to open a small window (say 100x100) to a new page.

    Like so:
    <body onLoad="javascript:void(window.open(URL, name [, features]));">

    This page is a .cgi page whose sole content is the Perl hit counter. Instead of a <META> tag refresh, try sending a content header refresh (which are more widely supported, IMX):

    In Perl:
    print "Content-type:text/html\n";
    print "Refresh:X; URL=http://www.site.com/thisDocument.cgi\n\n";
    print "<html>";
    # Here is you code for the actual web page hit counter
    Where X Is the number of seconds between refreshes. Don't set it too low (no less than 3, I recommend 5) because you run the risk of sending a new request before the current one is completed. That will DOS your server eventually.

    Alternately, you could use the setTimeout() JavaScript command on your main page to force a refresh by sending a document.open() command to a named small window.
  5. da chicken

    da chicken MajorGeek

    Actually, you could probably use an <IFRAME> (inline frame) instead of a new window. Only problem there is that Mozilla and Opera don't support it well. But if you don't care about 5% of the INternet, you're good to go.
  6. goldfish

    goldfish Lt. Sushi.DC

    to get around that you could have the script check the user agent string to find out if its Mozilla or Opera, and if it isnt, make the IFrame, but if it is open the window.

Share This Page

MajorGeeks.Com Menu

MajorGeeks.Com \ All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ NEW! PC Games \ System Tools \ Macintosh \ Demonews.Com \ Top Downloads

MajorGeeks.Com \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds