When URL is provided in href, .preventDefault() gets clobbered
When I have a click event and preventDefault on the event, if it has event tracking, it no longer prevents the link from going through. it registers the event, but my javascript no longer runs properly.
This does NOT happen when # is provided for the href.
Hi there,
Thanks for that. I'm struggling to follow what you mean. Could you perhaps post a code sample for me to follow so I can see what is going wrong first hand?
Many Thanks! :)
My use was tracking events on something that had a javascript function that did some show/hide stuff, but has a fallback URL in the href of the anchor so that it still does something if JS fails for one reason or another. If you put a real URL in the anchor, the plugin sees it, intercepts it and takes the user to that page (ignoring the e.preventDefault in my code). This looks to be because it's checking to see if it's NOT a # and if it's not, it runs the intercept to add the timeout and then sends the browser to the url.
I'll add a code example later today if I can.
Here's a gist with an html page: https://gist.github.com/brob/3e244abd2b583773318e
It's very very simple. My use case has a more complex function than just a console log, but i hope it helps illustrate the point.
In my fix i'm passing a data attribute (data-ga-nopass="true") into my anchor to stop the default behavior of the plugin
Oh yeah, that's really obvious now sorry. I'll get that implemented asap. Thanks.