I need to look for clicks on anchor tags when and when they occur and register them. The jQuery click delegate event handler for clicks stops the default link behavior in IE (i.e. clicking on the links does not lead me to a new page or whatever it really should have done), while everything works fine in Firefox.
I would be happy if someone in the community helped me understand this.
SAMPLE CODE:
function logLink(event,target) { //no logging for right click if(event.which<3) { if(filterLinks(target)) { alert('This will log data'); return true; } } return true; } /* *Method to filter all html links which are to be logged */ function filterLinks(linkObj) { //go into second phase only if the passed object is a link. if(linkObj.tagName == 'A') { alert('second phase') if( linkObj.hostname==undefined ||linkObj.hostname==''|| linkObj.hostname==null || $(linkObj).attr('href')=='#' || (!$(linkObj).attr('href')) || $(linkObj).attr('href').beginsWith('javascript',true) || $(linkObj).attr('href').beginsWith('mailto',true)) { alert('native code'); $(linkObj).css('background','gray'); return false; } for(var i=0;i<linkObj.attributes.length;i++) { if( !$.browser.msie && anchorTagProperties.indexOf(linkObj.attributes[i].nodeName)<0 ) { alert('redenned tag has an unknown attribute' + linkObj.attributes[i].nodeName); $(linkObj).css('background','red'); return false; } } return true; } else { return false; } } $(function (){ var testVar=undefined; //adding delegate listener for trackedLink class $('body').delegate(".trackedLink", "mouseup", function(event){ alert('mouseup'); var returnValue =logLink(event,this); return true; }); });
source share