JavaScript application Example: Point out the statistic device

Source: Internet
Author: User
Tags date bind header tagname tostring window wrapper
Javascript| Statistics | Application example

FF defaults to no change status
opera9 Test passed
IE6 Test passed

This thing is for the statistical department, analysis of user habits to improve the layout of the site.
It's just a little something to play with, so a lot of places aren't ideal.

The Save () method is to save the record, not carefully, you should add a Judge browser, and then decide to use IMG or IFRAME, to ensure that the request will be sent out.
The onclick () method is executed when the event is triggered.

How to use:

Add to any page

CODE:
Script src= "Clickout.js" ></script>

It is best to put it in front of </body> to prevent the onclick event from overwriting.

Clickout.js

CODE:

/*
* Description: Point out the statistical device
* Author: Dengwei
* Date: 2006-07-25
* Version: v1.0
*/

function ClickOut ()
{
This.oco = null;
This.src_onclick = null;
This.isdebug = True | | "Status"; Changed into This.isdebug = "status"; You can show it in the Window.status.

This.debug = function (ARG) {
if (This.isdebug = = "status") Window.status = Arg.tostring ();
else if (this.isdebug) alert (arg.tostring ());
}

This.save = function () {
var surl = "clickout.php?";
sURL + + "tag=" + encodeuricomponent (This.click_tag);
sURL + + "&type=" + encodeuricomponent (This.click_type);
sURL + + "&src=" + encodeuricomponent (THIS.CLICK_SRC);
sURL + + "&text=" + encodeuricomponent (this.click_text);
This.oco = document.createelement (' <div id= "ClickOut" style= "width:0px;height:0px;" ></div> ');
Document.body.appendChild (This.oco);
document.getElementById ("ClickOut"). InnerHTML = ' return true;
}

This.onclick = function (args) {
if (This.src_onclick!= null) This.src_onclick (e);
var obj = event.srcelement;
var tag = Obj.tagName.toLowerCase ();

this.click_id = Obj.id?obj.id:null;
This.click_class = Obj.classname?obj.classname:null;
This.click_name = Obj.name?obj.name:null;
This.click_tag = tag;
This.click_parent = obj;
This.click_obj = obj;
This.click_path = tag;

if (tag = = "a") {
This.click_type = "text";
THIS.CLICK_SRC = Obj.href;
This.click_text = obj.innerhtml;
}
else if (tag = "img") {
This.click_type = "pic";
THIS.CLICK_SRC = OBJ.SRC;
This.click_text = Obj.alt;
}
else if (tag = = "Font" | | tag = "B" | | | tag = "strong") {
This.click_type = "text";
THIS.CLICK_SRC = "";
This.click_text = obj.innerhtml;
}
else {
This.click_type = "Layer";
THIS.CLICK_SRC = "";
This.click_text = obj.innerhtml;
}

This. GetParent ();

This.debug (This.click_path);
Dosave ();
}

This. GetParent = function () {
if (!this.click_parent.parentnode.tagname) return;
This.click_parent = This.click_parent.parentNode;
This.click_path = this.click_parent.tagName.toLowerCase () + "[" +
(this.click_parent.id?) ("ID:" + this.click_parent.id): "") +
(This.click_parent.className?) (", CLASS:" + this.click_parent.className): "") +
(This.click_parent.name?) (", NAME:" + this.click_parent.name): "") +
"]" + ">" + this.click_path;
This. GetParent ();
}
}

Instance
var Objco = new ClickOut ();
Objco.src_onclick = Document.onclick;

function Click_tmp () {
Objco.onclick ();
}
function Dosave () {
Objco.save ();
}

Bind Event
Document.onclick = click_tmp;

Demonstrate:

Run Code Box

<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01//en" "HTTP://WWW.W3.ORG/TR/HTML4/STRICT.DTD" ><ptml><pead> <title>layout 16</title><meta http-equiv= "Content-type" content= "text/html"; Charset=iso-8859-1 "><meta name=" generator "content=" Hapedit 3.1 "><style type=" Text/css ">html,body{ margin:0;padding:0}body{font:76% arial,sans-serif}p{margin:0 10px 10px}a{display:block;color: #981793;p adding:10px}div#header h1{height:80px;line-height:80px;margin:0; Padding-left:10px;background: #EEE; color: #79B30B}div#content p{line-height:1.4}div#navigation{background: #B9CAFF }div#extra{background: #FF8539}div#footer{background: #333; color: #FFF}div#footer p{margin:0;padding:5px 10px}div# Wrapper{float:left;width:100%}div#content{margin-right:400px}div#navigation{float:left;width:200px;margin-left :-200px}div#extra{float:left;width:200px;margin-left:-400px}div#footer{clear:left;width:100%}</style> </pead><body><div id= "Container" ><div id="Header" ><p>header</p></div><div id= "wrapper" ><div id= "content" ><p>< strong>1) Content here.</strong> column Long long column very long fill fill fill long text text column text sill Y very make long very fill silly make to long make text fill very long text column silly silly very column long very col Umn filler fill long filler long silly very long silly silly silly long filler make column filler make silly long lon G Fill very.</p><p>very make-fill silly long long filler column long make silly silly column filler fill Fill very filler text fill filler column make-fill make-text very make make very fill-fill long make very filler column ve Ry long very filler silly very make filler silly make make column column </p><p>fill long make long text very Make long fill column make text very silly column filler silly text fill text filler filler filler T filler fill column filler make sIlly Make-text-fill make very filler column very </p><p>column-text long column make silly long text fill Er silly very very very long filler fill very fill silly very make make filler text filler text make silly text long Fill fill make text fill long-text very silly long filler filler fill silly long make column make silly long column L Ong make very </p></div></div><div id= "navigation" ><p><strong>2) navigation .</strong> Long long fill filler very fill column column silly filler very filler fill fill filler text fill very si lly fill text filler silly silly filler fill very make Fill column text column very very column fill fill very silly colum N Silly silly fill fill long filler </p></div><div id= "Extra" ><p><strong>3) more Stuff .</strong> very text make long column make filler fill make column column silly filler text silly column fill silly Fill column text filler make TeXT Silly filler make filler very silly make text very very text to long filler very make column make silly column fill s Illy column long make silly filler column filler silly long long column fill silly column very </p></div><d IV id= "Footer" ><p>here it goes the footer</p></div></div><script>/* * Description: Point out the statistical device * Author: 邓威 * Date: 2006-07-25 * Version: v1.0 */function clickout () {this.oco= null;this.src_onclick= null;this.isdebug= true | | "Status"; this.debug= function (ARG) {if (This.isdebug = = "status") Window.status = arg.tostring (); else if (this.isdebug) Alert (arg.tostring ());} this.save= function () {var surl = "clickout.php?"; sURL + + "tag=" + encodeuricomponent (this.click_tag) sURL + = "&type=" + encodeuricomponent (this.click_type); sUrl = " &src= "+ encodeuricomponent (THIS.CLICK_SRC); sURL + =" &text= "+ encodeuricomponent (this.click_text); This.oCO = Document.createelement (' <div id= "ClickOut" style= "width:0px;height:0px;" ></div> ');Document.body.appendChild (This.oco);d Ocument.getelementbyid ("ClickOut"). InnerHTML = ' '; return true;} this.onclick= function (args) {if (This.src_onclick!= null) This.src_onclick (e); var obj = event.srcelement;var Tag = obj. Tagname.tolowercase (); this.click_id= obj.id?obj.id:null;this.click_class= Obj.classname?obj.classname:null; This.click_name= obj.name?obj.name:null;this.click_tag= tag;this.click_parent= obj;this.click_obj= obj;this.click_ Path= tag;if (tag = "a") {This.click_type = "text"; this.click_src = Obj.href;this.click_text = obj.innerhtml;} else if (tag = = "img") {this.click_type = "pic"; this.click_src = Obj.src;this.click_text = Obj.alt;} else if (tag = = "Font" | | | tag = "B" | | tag = "strong") {This.click_type = "text"; this.click_src = ""; This.click_text = obj.innerhtml;} else {this.click_type = "layer"; this.click_src = ""; this.click_text = obj.innerhtml;} This. GetParent (); This.debug (this.clicK_path);d Osave (); This. getparent= function () {if (!this.click_parent.parentnode.tagname) return;this.click_parent = This.click_ Parent.parentnode;this.click_path = this.click_parent.tagName.toLowerCase () + "[" + (this.click_parent.id?) ID: "+ this.click_parent.id": "") + (This.click_parent.className? (", CLASS:" + this.click_parent.className): "") + ( This.click_parent.name? (", NAME:" + this.click_parent.name): "") + "]" + ">" + this.click_path;this. GetParent ();} instance var Objco = new ClickOut ()//Save the original onclick event Objco.src_onclick = document.onclick;function click_tmp () {Objco.onclic K ();} function Dosave () {Objco.save ();} Bind Eventdocument.onclick = click_tmp;</script></body></ptml>

[Ctrl + A ALL SELECT hint: You can modify some of the code, and then run]



Related Article

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.