Search code examples
firefox-addonclicklistener

Addon tracking click on result Google not working?


Thank you for your quick reply. I want to track a link based on google search results.

It works in some cases as nomal but doesn't work on links that are google search results, eg https:// www.google.com.vn /?gws_rd=ssl#q=google+adwords. I will try to reproduce problem step by step:
1. Install addon with handle event click following code.

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. Go to link https://www.google.com.vn/?gws_rd=ssl#q=google+adwords on the browser.
  2. Click any link on search result, eg "Google AdWords – Online advertising by Google" link (http:// adwords. google.com). Expected result: Alert message like "Link: adwords.google.com"; But it doesn't alert any things. In the console log, it show a js error message like event is null". Please help me!!!

Solution

  • Update based on your code you edited in:

     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: shame on the person voting to close your topic, just because you don't type english so well.