javascript/php - record click destination before redirect
Say I have the link:
<a href="http://www.google.com">google</a>
Is there any way I can record the click (with php/sql)? For example an onclick event to load ajax? Would the ajax run before the page redirects? I want to avoid:
<a href="rec开发者_C百科ord_click.php?url=http://www.google.com">google</a>
You could change your link to:
<a href="test.php" onclick="javascript: recordClick(this); return false;">TEST</a>
And then use the function:
function recordClick(t) {
//Insert AJAX here. t contains the URL
document.location = t;
}
You could then wait for the AJAX request to complete before using the document.location part. However I would suggest simply using a separate file to log clicks like you have already suggested because it is an immediate action that doesn't require JS to be on, and that provides immediate feedback.
精彩评论