Clickdemo.html: This file contains HTML and AJAX code associated with the link.
clicktrack.php:php return operation Information
<body>
<a href= "http://www.111cn.net" onclick= "DoWork (this);" >test</a>
</body>
JS Code
The Web page effects code is a bit more, but here only DoWork (), this function will handle the mouse click, get the source and target location, and call clicktrack.php Update statistical information
function DoWork (Element) {
Httpobject = Gethttpobject ();
if (httpobject!= null) {
DST = Element.href;
src = document.location.href;
Httpobject.open ("Get", "clicktrack.php?src=" +src+ "&dst=" +dst, true); Httpobject.send (NULL);
Httpobject.onreadystatechange = Setoutput;
}}
See the full example below
<!doctype HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/ Xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<TITLE>AJAX Click Tracking example</title>
<script language= "javascript" type= "Text/javascript" >
function Gethttpobject () {
if (Window.activexobject) return the new ActiveXObject ("Microsoft.XMLHTTP");
else if (window.xmlhttprequest) return new XMLHttpRequest ();
else {alert ("Your browser does not support Ajax.");
return null; } }
Change the value of the Outputtext field
function Setoutput () {return true;} Implement business logic
function DoWork (Element) {
Httpobject = Gethttpobject ();
if (httpobject!= null) {
DST = Element.href;
src = document.location.href;
Httpobject.open ("Get", "clicktrack.php?src=" +src+ "&dst=" +dst, true);
Httpobject.send (NULL);
Httpobject.onreadystatechange = Setoutput;
}
}
var httpobject = null; var src = null; var dst = null;</script>
<body>
<a href= "http://www.111cn.net" onclick= "DoWork (this);" > Test </a>
</body>