I have this jQuery scrip which counts the number of clicks on a certain div and then, at the second click, it redirects the user to a custom url. The script works and counts the clicks even if the user leaves the page.
function traffic(){
var traffic = $('.model').data("traffic");
if(traffic){
var nbc = localStorage['nbc']||0;
$('.model a').click(function(){
localStorage['nbc'] = ++nbc;
if(nbc%2==0){
window.open(traffic, '_blank');
}
});
}
}
Now, I am a total newb with ajax (actually i do not know anything about it, I am a webmaster not a programer with an overdue deadline) and I need some help:
I need an ajax call that, on the time of the action, will send the second click into a php variable so I can use a code like the following (and avoid the "window.open" method which is in conflict with another script I use on the page):
if($number_of_clicks == 2){
echo 'my new link, a method which will save me from using window.open';
} else {
echo 'my ragular link';
}
Can it be done?
UPDATE
Let me explain, my fault for not being clearer.
User enters my site and clicks on a normal link. Jquery stores that event and the user goes to an internal page.
When he hits the home button, ajax sends that event to a php variable, so I'll have $myvar=1.
Now I can change that certain link on my site with:
if($myvar == 1){
echo 'my new link';
} else {
echo 'my ragular link';
}
And now, when the user clicks on that link, he will go to the new link.
Hope I've been a little clearer.
Ty!