ff          默認不讓改 status
opera9  測試通過
ie6   測試通過

這東西是給統計部門用的,分析用戶習慣以改良網站佈局。
只是寫著玩的小東西,所以很多地方不太理想。

save() 方法是保存記錄的,沒仔細做,應該再加個判斷瀏覽器,然後決定用 img 還是 iframe,以保證 request 一定能發出去.
onclick() 方法是觸發事件時執行的

使用方法:
在任意頁面中加入

程序代碼 程序代碼
script src="clickout.js"></script>



最好是放在 </body> 前面,目的是防止 onclick 事件覆蓋。

clickout.js

程序代碼 程序代碼
/*
* 說明:點出統計器
* 作者:鄧威
* 日期: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=" _fcksavedurl=""" + 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;



演示:到處點點看喔!
點此下載

創作者介紹
創作者 kevin0523 的頭像
kevin0523

新‧夢想

kevin0523 發表在 痞客邦 留言(0) 人氣()