views:

129

answers:

3

I am using http://bit.ly/5NNAIa, and I have it tracking an outbound link, but I want my page to be valid.

This is the error I am getting: There is no "OnCick" attribute

The HTML is:

<p>View some of our student produced videos 
on <a href="http://www.youtube.com/user/johndoe" onClick="javascript: pageTracker._trackPageview('/outgoing/youtube.com/user/johndoe');" rel="external">YouTube!</a></p>

I added this do my js embed file, to track all outgoing links

$(document).ready(function() {
    $('a[href^=http]:not("[href*=://' + document.domain + ']")').click(function() {
     pageTracker._trackPageview('/out/'+$(this).attr("href"));
    });
});

So now my js embed file looks like this below. I notice I call $(document).read(function() { at the beginning of both snippets, should they both go into one?

$(document).ready(function() {
    // opens links into separate window
    $('A[rel="external"]').click( function() {
     window.open( $(this).attr('href') );
     return false;
    });
});

$(document).ready(function() {
    $('a[href^=http]:not("[href*=://' + document.domain + ']")').click(function() {
     pageTracker._trackPageview('/out/'+$(this).attr("href"));
    });
});
+4  A: 

Use an event listener to handle the onclick.

gms8994
A: 

As gms8994 implied, attach click event handlers to the links you want to track, on the load event of window.

If you don't want to do that, change the page's document type declaration to point to the Transitional XHTML DTD and use "onclick" (all lower case).

gWiz
onClick is invalid in XHTML 1.0 Transitional
David Dorward
I should have added that the attribute must be lower-case, i.e. "onclick" is good, "onClick" is invalid.
gWiz
+1  A: 

Unless you are using some highly obscure or ancient version of HTML, you are probably using XHTML, which is case sensitive and all lower-case. Change it to onclick.

David Dorward