Javascript error in tableheader.js: $("td" + location.hash).offset() is undefined
markus_petrux - April 12, 2009 - 04:34
| Project: | Drupal |
| Version: | 7.x-dev |
| Component: | javascript |
| Category: | bug report |
| Priority: | critical |
| Assigned: | Unassigned |
| Status: | duplicate |
| Issue tags: | JavaScript |
Description
Hi,
The following piece of code in tableheader.js causes javascript error $("td" + location.hash).offset() is undefined when a hash is present in the URL that has no relation with table cells.
if (prevAnchor != location.hash) {
if (location.hash != '') {
var scrollLocation = $('td' + location.hash).offset().top - $(e).height();
$('body, html').scrollTop(scrollLocation);
}
prevAnchor = location.hash;
}The error happens when the selector 'td' + location.hash does not match any element. In that case, offset().top is undefined.
I think it could be fixed by adding a condition like this:
if (prevAnchor != location.hash) {
if (location.hash != '' && $('td' + location.hash).size()) {
var scrollLocation = $('td' + location.hash).offset().top - $(e).height();
$('body, html').scrollTop(scrollLocation);
}
prevAnchor = location.hash;
}I'm making the issue critical because this issue causes javascript errors when a hash is present in the URL that does not match a TD identifier. This javascript error breaks all the javascript present in the site, including ads, analytics, etc.
Please, consider backporting this fix to D6 too.

#1
I guess this probably needs to be fixed first in dev. Attached patch against HEAD.
#2
The last submitted patch failed testing.
#3
wow! and now? Why the patch failed?
hmm... adding -p option to the diff command to see if that helps.
#4
The last submitted patch failed testing.
#5
hmm... this is kind of frustrating, isn't it? All you can see here is that the patch fails, but it doesn't tell you why.
I hate to turn this into a support question, but can someone drive me in the correct direction?
#6
Dup: #325810: Issue when using dimensions jquery plugin in tableheader.js