添加跟踪点击结果Google无法使用?

时间:2014-07-21 09:09:47

标签: firefox-addon clicklistener

感谢您的快速回复。 我想根据谷歌搜索结果跟踪链接。

在某些情况下,它适用于正常但不适用于Google搜索结果的链接,例如https:// www.google.com.vn /?gws_rd = ssl#q = google + adwords。 我将尝试逐步重现问题:
1.使用handle事件安装插件,单击以下代码。

function handleWindowClick(event) {
            var origEl = event.target;
            if(origEl.tagName == 'A') {
                // do some things with event link: origEl.toString();
                alert("Event Link: " + origEl.toString());
            } else if(origEl.parentNode.tagName == 'A') {   
                alert("Event Link: " + origEl.parentNode.toString());
            } else if(origEl.tagName == 'SPAN') {
                alert("Span  is clicked"); 
            }
    }

window.addEventListener('click', handleWindowClick, false);
  1. 转到浏览器上的https://www.google.com.vn/?gws_rd=ssl#q=google+adwords链接。
  2. 点击搜索结果中的任意链接,例如“Google AdWords - Google在线广告”链接(http:// adwords.google.com)。 预期结果: 提醒消息,例如“链接:adwords.google.com”; 但它不会提醒任何事情。在控制台日志中,它显示一个js错误消息,如event为null“。 请帮帮我!!!

1 个答案:

答案 0 :(得分:0)

根据您编辑的代码进行更新:

 function handleWindowClick(event) {
            var origEl = event.target;
            if(origEl.tagName == 'A') {
                // do some things with event link: origEl.toString();
                alert("Event Link: " + origEl.toString());
            } else if(origEl.parentNode.tagName == 'A') {   
                alert("Event Link: " + origEl.parentNode.toString());
            } else if(origEl.tagName == 'SPAN') {
                alert("Span  is clicked"); 
            }
    }

window.addEventListener('click', handleWindowClick, false);

ps:投票关闭你话题的人感到羞耻,只因为你不能很好地输入英语。