Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Feb 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Javscript Mouseover Counting

    Hi ALL!

    I have page with those key-word ads on it. For example:

    "And then reboot your SQL Server and relogin to see the changes"

    When you mouse over "SQL Server" you see a pop-up add from an advertiser that does SQL Server performance tuning.

    At any rate: When you click the add, my javascript catches and adds +1 to the count of the number of clicks before it open the advertiser's webpage.

    This way I can keep track of the number of times it is clicked.

    ***All this is pretty standard and easily done***

    But my curiosity wants me to count the number of times the mouse hover over the word, which I'll compare to the number of clicks (ie: 1080 hovers vs 13 clicks) to get a percentage of mouseovers vs mouseclicks.

    Does anyone know the code I can use to do this? Is this possible? Are there any performance issues inherit with this type of javascript that will be getting called ALOT without being able to move to a new page (hence my existing cgi-bin perl script I call for click-counts won't work)


    THANKS for any and all help!!!!!!!

  • #2
    Senior Coder
    Join Date
    Nov 2006
    Posts
    1,000
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Lots of different ways to do this. Here is one of em.

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html>
      <head>
        <title>Junque</title>
        <style type="text/css">
          span { color: red; }
        </style>
        <script type="text/javascript">
          var overObj = null;
    
          function doIt() {
            var s = "Over: <br/>";
    
            for (var key in overObj) {
              s += "\xA0\xA0'" + key + "' - " + overObj[key] + " times<br/>";
            }
    
            var adiv = document.getElementById("adiv");
            adiv.innerHTML = s;
          }
    
          function over(o) {
            ++overObj[o.id];
            
            doIt();
          }
    
          window.onload = function () {
            if (!overObj) {
              overObj = {};
              var t = document.getElementsByTagName("span");
              for (var i = 0; i < t.length; i++) {
                overObj[t[i].id] = 0;
                t[i].onmouseover = function () { over(this); };
              }
            }
          };
        </script>
      </head>
      <body>
        <div>
          <div><span id="how">How</span> are you <span id="doing">doing</span> on this fine <span id="day">day</span>?
          <br />
          <div id="adiv"> </div>
        </div>
      </body>
    </html>
    david_kw

  • #3
    New to the CF scene
    Join Date
    Feb 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Ahhh, but what about...

    yes thanks but,this will show the user how many times they've hovered over the object, but how would I find out? This number needs to get saved somehow. And since Javascript cannot access the server (to say change the information in count.txt) It needs to call something else......without moving to a new page.

    Any more ideas?

  • #4
    Senior Coder
    Join Date
    Nov 2006
    Posts
    1,000
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That was just an example how to count mouseovers. Since you are using a cgi script from a form, I'd think the best way to do it would be write the numbers in hidden fields then do your analysis on submit. Or you could use ajax to do it asynchronously.

    david_kw


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •