Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
The jQuery selectors used on Line 42 of googleanalytics.js..
if (ga.trackMailto && $(this).is("a[href^=mailto:],area[href^=mailto:]")) {
..are no longer valid in jQuery 1.7 +, the attributes need quotes, eg:
if (ga.trackMailto && $(this).is("a[href^='mailto:'],area[href^='mailto:']")) {
These are safe in all versions of jQuery.
Most modern browsers handle it without issue, but IE8 and below throw errors.
Comments
Comment #1
hass CreditAttribution: hass commentedhttp://api.jquery.com/attribute-starts-with-selector/
Do you have a link where this change is documented? Latest v1.8.2 docs allow the value to be unquoted.
Comment #2
hass CreditAttribution: hass commentedComment #3
hass CreditAttribution: hass commentedIs this a duplicate of #1113550: JavaScript: Uncaught TypeError - Cannot call method 'replace' of undefined?
Comment #4
SecureTrading CreditAttribution: SecureTrading commentedSorry, haven't checked up on the thread in a while. I had seen some discussion on the handling of quotes in attribute selectors, unfortunately can't remember where this was. I don't think I highlighted enough that this is only specific to jQuery 1.7+ on IE<8, non quoted attribute selectors ARE valid, but seemingly not properly supported in older IE versions.
A curious note on this page:
http://api.jquery.com/category/selectors/attribute-selectors/
States that only simple identifiers should be unquoted, could be that the ":" in "mailto:" disqualifies it?
Every example on that page also uses quotes.
Are you able to replicate the bug/solution in IE8?
Comment #5
hass CreditAttribution: hass commentedThanks for sharing this, but I'm still confused as it is not clear to me what a simple identifier is.
It also sounds strange to me that I do not have a IE8 next to me for testing. Something I need to change. But the more problematic is that I have a Drupal 7 with jQuery v1.4.4 only and as these jQuery upgrades have always caused issues only inside Drupal I'm not sure why I should try it.
As we have never seen this with jQuery v1.4.4 it may be a bug of 1.7+. I would suggest you file a issue against jquery first and we see what the jquery guys say. Please post the bug tracking link here, too.
Comment #6
hass CreditAttribution: hass commentedPer http://api.jquery.com/category/version/1.7/ it looks like there have been chances to
is()
function that is used here.Comment #7
hass CreditAttribution: hass commentedMaybe one of these changed introduced it:
Comment #8
SecureTrading CreditAttribution: SecureTrading commentedThanks for the feedback, I wasn't entirely sure on their usage of 'simple identifier' either, it seems to be any alphanumeric string, so as soon as punctuation is used (e.g ":" or a space), it needs to be quoted. I'm not entirely sure it's a jQuery bug.
Quote from this page (It appears to have been a change in or around 1.6)
http://bugs.jquery.com/ticket/9351#comment:2
And again on the API reference:
http://api.jquery.com/attribute-equals-selector/
I think it comes back to "mailto:" not being an alphanumeric 'word', and should be treated as a string.
Quoting the attribute value works on all versions of jQuery, I think it'd be a worthwhile update to the module as the version of jQuery that is available is not guaranteed to be the version included in Drupal core.
Comment #9
hass CreditAttribution: hass commentedLet's file a bugcase and get the confirmation that this is a new design or if it's a bug. The jquery docs are not clear to me and need to be fixed. We both see how unclear it is. Others may run into the same DX issues.
Comment #10
SecureTrading CreditAttribution: SecureTrading commentedNot sure that's necessary, I think the following references should clear it up.
As before, from the Attribute Selector API page
http://api.jquery.com/category/selectors/attribute-selectors/
After digging around on W3's CSS spec, I found the following information:
http://www.w3.org/TR/selectors/#attribute-selectors
A CSS Identifier is defined here:
http://www.w3.org/TR/CSS21/syndata.html#value-def-identifier
A CSS String can be anything in the charset, inside quotes.
So, "mailto:" contains characters outside of [a-zA-Z0-9], "-", "_" and doesn't qualify as an Identifier, suggesting it must be passed as a string, with quotes. It might be possible to escape the colon also, but I haven't tested this. e.g:
a[href^=mailto\:
Comment #11
hass CreditAttribution: hass commentedWell in such a case we quote it better. However jQuery docs needs an update to clarify this. At least as it has worked several years.
Comment #12
hass CreditAttribution: hass commentedhttp://drupalcode.org/project/google_analytics.git/commit/3c85b1c
http://drupalcode.org/project/google_analytics.git/commit/9dc951c
http://drupalcode.org/project/google_analytics.git/commit/363336d