Ajax PHP HTML record article click Collection Times

Source: Internet
Author: User

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 "/>
&LT;TITLE&GT;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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.