Hi, I'm trying to track outgoing links on my site. When the user clicks on a link, I want them to be taken to the site (href) and I also want a background script call that records the link (via Ajax). The script I have worked in development mode but only works occasionally in production mode. Is it possible to link to a new site and call an ajax request at the same time? Thanks
on 2008-07-04 15:33
on 2008-07-04 16:30
Yup, like this:
<a href="moo.htm" onclick="writeLog('moo');return false">
...where writelog() is a function that does your Ajax call.
Alternately, you can just get Google Analytics to log it:
http://www.google.com/support/analytics/bin/answer...
on 2008-07-04 18:38
Thanks for the reply Diodeus. I see what you're saying, but won't the return false stop the link from going to the href location?
on 2008-07-04 18:54
Thanks for the reply Diodeus. I see what you're saying, but won't the return false stop the link from going to the href location?
on 2008-07-04 19:11
Nope, it does the opposite - it returns control to the link from being intercepted by Javascript.
on 2008-07-04 23:01
On 4.7.2008, at 20.11, Diodeus wrote: > > Nope, it does the opposite - it returns control to the link from being > intercepted by Javascript. Err, no, it doesn't. It stops the link from being followed. I even had to test this in a browser to make sure I'm not imagining things: <a href="http://google.com" onclick="console.log('Testing'); return false;">Test</a> That certainly doesn't go anywhere. Using true instead does lead to google. //jarkko -- Jarkko Laine http://jlaine.net http://dotherightthing.com http://www.railsecommerce.com http://odesign.fi
on 2008-07-05 18:57
On Jul 4, 2008, at 5:00 PM, Jarkko Laine wrote:
>
Maybe if your log action returned true, you could do
onclick="return console.log('Testing');"
Walter
on 2008-07-05 22:03
On 5.7.2008, at 19.56, Walter Lee Davis wrote: >> Err, no, it doesn't. It stops the link from being followed. I even >> had to test this in a browser to make sure I'm not imagining things: >> >> > > Maybe if your log action returned true, you could do > > onclick="return console.log('Testing');" Sure, but that wasn't the point :-) The point was that true let's the browser to follow the link, false stops it. The log msg was there just for me to see that the js was executed. //jarkko -- Jarkko Laine http://jlaine.net http://dotherightthing.com http://www.railsecommerce.com http://odesign.fi