I create a unique hit/click counter works on ip.
To display the number of clic, I use on the body tag the onload function.For example:
<body class="homepage" onload="affiche_compteur('compteur1'); affiche_compteur('compteur2');affiche_compteur('compteur3');affiche_compteur('compteur4');affiche_compteur('compteur5');affiche_compteur('compteur6');">
affiche_compteur (in french)= display_counter
I need to call with onload each click counter present in my html page. (It works for hardcoded element, however in my case I have appended element on document ready that are not present in my html page (not hardcoded))
Is there a way to get every id of click counter to avoid to add each counter onload?
Here my ajax script :
function getXhr(){ var xhr = null; if(window.XMLHttpRequest) { xhr = new XMLHttpRequest(); } else if(window.ActiveXObject) { try { xhr = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xhr = new ActiveXObject("Microsoft.XMLHTTP"); } } else { alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); xhr = false; } return xhr;};function affiche_compteur(id_clics){ var xhr = getXhr(); xhr.onreadystatechange = function() { if(xhr.readyState == 4 && xhr.status == 200){ document.getElementById(id_clics).innerHTML = xhr.responseText; } }; xhr.open('POST', './compteur/affiche_compteur.php', true); xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); xhr.send('compteurId='+id_clics);}
Here the html for clicked element:
<div class="element blog " id="_13"><a class="link" href="/portfolio/dock.html" onclick="gestionClic('compteur13');"></a></div><div class="element blog " id="_12"><a class="link" href="/portfolio/dock.html" onclick="gestionClic('compteur12');"></a></div><div class="element blog " id="_11"><a class="link" href="/portfolio/dock.html" onclick="gestionClic('compteur11');"></a></div>
Sorry for my English, I'm French.