Javascript Event.Target问题与锚点

时间:2015-04-04 20:56:42

标签: javascript adobe-analytics

这个链接管理器有一个缺陷,它使用event.target来搜索锚标签,但它会跳过包含IMG,SPAN,DIV等的锚标签。我无法弄清楚如何让它包含任何对象锚标签包装。有人有想法吗?

以下是演示此问题的演示页:http://tinyurl.com/nxc7bpx

这是原始插件:

/* Exit Link Manager v0.5 */
function getLinks() {
    for (var i = 0; i < document.links.length; i++) {
        lnk = document.links[i];
        if (lnk.addEventListener) {
            lnk.addEventListener('click', sendExitConversion, false)
        } else if (lnk.attachEvent) {
            lnk.attachEvent('onclick', sendExitConversion)
        }
    }
}

function setBodyOnload() {
    if (window.addEventListener) {
        window.addEventListener('load', getLinks, false)
    } else if (window.attachEvent) {
        window.attachEvent('onload', getLinks)
    }
}
setBodyOnload();

function sendExitConversion(event) {
    var obj;
    event = event ? event : window.event;
    var s = s_gi(s_account);
    if (event.target) {
        obj = event.target
    } else if (event.srcElement) {
        obj = event.srcElement
    }
    if (obj.href) {
        var exitLinks = s.linkInternalFilters;
        var exitArray = exitLinks.split(',');
        if (s.trackExternalLinks == false) {
            isExitLink = true;
            for (i = 0; i < exitArray.length; i++) {
                if (obj.href.toLowerCase().indexOf(exitArray[i].toLowerCase()) > -1) {
                    isExitLink = false
                }
            }
            exitURLStart = obj.href.substring(obj.href.indexOf('//') + 2, obj.href.length);
            if (exitURLStart.indexOf('/') > -1) {
                exitURLEnd = exitURLStart.indexOf('/')
            } else {
                exitURLEnd = exitURLStart.length
            }
            var exitDomain = exitURLStart.substring(0, exitURLEnd);
            if (isExitLink) {

                /* SET YOUR EXIT LINK VARIABLES AND EVENTS HERE */
                s.linkTrackVars = "";
                s.linkTrackEvents = "";
                s.events = "";
                s.tl(this, 'e', exitDomain);
            }
        }
    }
}

1 个答案:

答案 0 :(得分:0)

因此,当我将obj = event.target更改为obj = currentTarget时,我现在可以检索链接数据。