[JS]点出统计器
作者:lnsoso 时间:2013-07-22 03:23:24
ff 默认不让改 status
opera9 测试通过
ie6 测试通过
这东西是给统计部门用的,分析用户习惯以改良网站布局。
只是写着玩的小东西,所以很多地方不太理想。
save() 方法是保存记录的,没仔细做,应该再加个判断浏览器,然后决定用 img 还是 iframe,以保证 request 一定能发出去.
onclick() 方法是触发事件时执行的
使用方法:
在任意页面中加入
CODE:
script src="clickout.js"></script>
最好是放在 </body> 前面,目的是防止 onclick 事件覆盖。
clickout.js
CODE:
/*
* 说明:点出统计器
* 作者:邓威
* 日期:2006-07-25
* 版本:v1.0
*/
function ClickOut()
{
this.oCO = null;
this.src_onclick = null;
this.isDEBUG = true || "status"; // 改成 this.isDEBUG = "status"; 就可以在 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 = '<img src="' + sUrl + '" style="display: none;" width="0px" height="0px" \/>';
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();
}
}
// 实例
var objCO = new ClickOut();
objCO.src_onclick = document.onclick;
function click_tmp() {
objCO.onclick();
}
function doSave() {
objCO.save();
}
// bind event
document.onclick = click_tmp;
演示:
运行代码框
[Ctrl+A 全部选择 ]
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
细化解析:SQL Server数据库的集群设计
浅谈pytorch池化maxpool2D注意事项
FCKeditor编辑器基本配置优化修改使用方法
Selenium+BeautifulSoup+json获取Script标签内的json数据
有效地使用 SQL事件探查器的提示和技巧
oracle SQL命令大全
一个asp正则替换的方法
楼层数横排比竖排好
![](https://img.aspxhome.com/file/UploadPic/20084/26/200842673425574s.jpg)
分享10个Js的小型库,效果真的很棒
HTML与CSS在Flash中的应用
Mootools 1.2教程(21)——类(二)
如何获取浏览器的更多信息?
博客使用标签是迟早的事
用户体验如何提升阿里巴巴的商业价值
![](https://img.aspxhome.com/file/UploadPic/20097/23/1-12s.gif)
php日期转时间戳,指定日期转换成时间戳
调试一段PHP程序时遇到的三个问题
从JavaScript的函数重名看其初始化方式
![](https://img.aspxhome.com/file/2023/3/55923_0s.gif)
Oracle数据库系统紧急故障处理方法
HTML5 的五个激动人心的特性
![](https://img.aspxhome.com/file/UploadPic/20091/2/html5_1-47s.jpg)