Skip to main content

Bug Tracker

Side navigation

#4996 closed bug (fixed)

Opened July 31, 2009 04:41PM UTC

Closed September 28, 2010 09:57PM UTC

Last modified March 13, 2012 05:50PM UTC

getBoundingClientRect causes 'Unspecified Error' in IE after ajax

Reported by: chack7 Owned by:
Priority: major Milestone: 1.4.3
Component: offset Version: 1.4.2
Keywords: Cc:
Blocked by: Blocking:
Description

In jQuery-1.3.2

Line 4176

Only occurs in IE

Reproduce details: Telerik RadTreeView recursed to set tree elements with droppable

Html text elements set to draggable

Works fine until the RadTreeView is updated with a ajax postback at which point, any attempt to drag and element results in 'Unspecified Error'

This does not occur in FireFox

Workaround: added the following modification

if ( document.documentElement["getBoundingClientRect"] )

jQuery.fn.offset = function() {

if ( !this[0] ) return { top: 0, left: 0 };

if ( this[0] === this[0].ownerDocument.body ) return jQuery.offset.bodyOffset( this[0] );

2009-07-31: Added try catch to resolve error IE caused by ajax update of controls

var box;

try {

box = this[0].getBoundingClientRect();

}

catch(ex) {

box = {top : 0, left: 0, right: 0, bottom: 0}

}

///////////////////////////////////////////////////////////////////////////////////

var doc = this[0].ownerDocument, body = doc.body, docElem = doc.documentElement,

clientTop = docElem.clientTop || body.clientTop || 0, clientLeft = docElem.clientLeft || body.clientLeft || 0,

top = box.top + (self.pageYOffset || jQuery.boxModel && docElem.scrollTop || body.scrollTop ) - clientTop,

left = box.left + (self.pageXOffset || jQuery.boxModel && docElem.scrollLeft || body.scrollLeft) - clientLeft;

return { top: top, left: left };

};

Attachments (1)
  • offset.zip (46.2 KB) - added by reiern70 March 24, 2010 10:51AM UTC.

    reproduces the problem with AJAX updates and offset function

Change History (14)

Changed August 02, 2009 08:07PM UTC by dmethvin comment:1

need: ReviewTest Case

Can you provide a test case? Catching and ignoring an error often isn't the right solution.

Changed December 17, 2009 02:02AM UTC by ckosti comment:2

I have run into the same problem. This will cause the error to occur:

$(document.createElement('div')).offset();

An odd case, I know, but I ran into a situation where JQuery UI is holding onto references to elements that had been replaced by AJAX calls, and then calling offset() on those elements, even though they are no longer in the document tree.

IE throws an error in this case when getBoundingClientRect() is called. Other browsers handle it by returning a rectangle with all zero values.

Changed March 10, 2010 06:21AM UTC by reiern70 comment:3

Hi,

I think I'm experiencing the same problem with jquery 1.4.2. After refreshing some part of the page with AJAX (using Wicket) all my draggable-dropables stop to work because of an error appearing on line

5942 var box = elem.getBoundingClientRect()

I think it is exactly the same problem... Right now I could provide a testcase consisting of a very simple Wicket application and instructions on how to reproduce the error. Would that be enough for the developers to try to fix this problem?

Regards,

Ernesto

Changed March 24, 2010 10:56AM UTC by reiern70 comment:4

Hi,

I just attached a test case showing this behavior (it does exactly what ckosti mentioned $(document.createElement('div')).offset();). I discover this problem while using drag-drop in combination with AJAX and went along and created

http://dev.jqueryui.com/ticket/5374

But this is clearly the same problem. This has been opened for many months already and is a clear HUGE limitation in using jQuery in combination with other AJAX frameworks. Any chance to get this fixed soon?

Best,

Ernesto

Changed April 07, 2010 03:27PM UTC by RSparkyC comment:5

I am having the same problem. Because we are doing ajax postbacks, we are getting the 'Unspecified Error' in IE when clicking on a draggable object. Is there still no fix for this other than manually editing the jQuery js files?

Changed April 27, 2010 01:59AM UTC by Rasetti comment:6

I'm having the same problem, using 1.4.2.

Any chances of fixing it for the next release?

Changed May 05, 2010 11:49AM UTC by pete comment:7

You can work around this without modifying the jQuery source.

1. before the ajax request is made, invoke the destroy method on draggable objects:

 $("#drag").draggable("destroy"); 

2. after the ajax response, setup your draggable elements again.


If using ASP.NET Ajax, you can invoke the destroy method like so:

Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(function(){
   $("#drag").draggable("destroy");
});

To set the draggable again, you can use .add_endRequest in the same manner as .add_beginRequest, or create a function called pageLoad in the global namespace that does the work. ASP.NET Ajax will invoke a pageLoad function (if it exists) any time a postback is made (real or ajax).

Changed May 20, 2010 01:06PM UTC by jharte comment:8

Hi,

I've hit this issue as well, while using the qTip plug-in: http://craigsworks.com/projects/qtip/

I'm using a couple of ASP.NET AJAX UpdatePanels on my page and I get the error after either of them is updated.

I've modified my copy of jQuery to handle the error as described in the initial bug report by chack7, but would really like to see this fixed in an official jQuery release.

Thanks!

Changed June 09, 2010 08:42PM UTC by thephatmann comment:9

I am seeing this issue with the DevBridge autocomplete plugin under IE7/8. The patch to offset( ) posted above fixes the issue, so I recommend that the patch get incorporated into the next jQuery release.

Changed June 13, 2010 02:23PM UTC by dmethvin comment:10

component: unfileddimensions

The test case boils down to this:

  $(document.createElement('div')).offset();

It's asking for the offset of an element that is not connected to the document! That's not a reasonable thing to do. Is there some information that .offset() could return for this case instead of an error that wouldn't simply mask the problem?

If you're experiencing this problem, use the IE8 debugger to break on the error, then look at the stack trace to determine what code is asking for the offset of an element that is not connected to the document. Then report a bug against that code.

If there are cases where jQuery core itself causes the problem, please attach them to this ticket.

Changed June 16, 2010 08:39PM UTC by slenzi comment:11

I was experiencing the same issue and found a thread on stackoverflow where someone posted a solution.

http://stackoverflow.com/questions/371468/looking-for-a-workaround-for-ie-6-7-unspecified-error-bug-when-accessing-offset

In jquery-1.4.2.js file on line 5493 there is the following line:

var box = elem.getBoundingClientRect()

if you replace that with this is works:

var box = null;
try { 
   box = elem.getBoundingClientRect();
} catch(e) {
   box = { top : elem.offsetTop, left : elem.offsetLeft }
};

Changed June 16, 2010 08:44PM UTC by slenzi comment:12

I meant line 5943 in jquery-1.4.2.js!!

Replying to [comment:11 slenzi]:

I was experiencing the same issue and found a thread on stackoverflow where someone posted a solution. http://stackoverflow.com/questions/371468/looking-for-a-workaround-for-ie-6-7-unspecified-error-bug-when-accessing-offset In jquery-1.4.2.js file on line 5493 there is the following line:
> var box = elem.getBoundingClientRect()
> 
if you replace that with this is works:
> var box = null;
> try { 
>    box = elem.getBoundingClientRect();
> } catch(e) {
>    box = { top : elem.offsetTop, left : elem.offsetLeft }
> };
> 

Changed August 03, 2010 07:50PM UTC by thephatmann comment:13

This bug has a test case and a suggested fix, so it should be incorporated into the trunk. But the bug has no owner, since the former owner left. How do we resolve this?

Changed September 28, 2010 09:57PM UTC by john comment:14

component: dimensionsoffset
milestone: 1.41.4.3
resolution: → fixed
status: newclosed
version: 1.3.21.4.2