Bug Tracker

Ticket #4996 (closed bug: fixed)

Opened 5 years ago

Last modified 3 years ago

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:
Blocking: Blocked by:

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.documentElementgetBoundingClientRect? )

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 top = box.top + (self.pageYOffset left = box.left + (self.pageXOffset
body.clientTop 0, clientLeft = docElem.clientLeft body.clientLeft 0,
jQuery.boxModel && docElem.scrollTop body.scrollTop ) - clientTop,
jQuery.boxModel && docElem.scrollLeft body.scrollLeft) - clientLeft;

return { top: top, left: left };

};

Attachments

offset.zip Download (46.2 KB) - added by reiern70 5 years ago.
reproduces the problem with AJAX updates and offset function

Change History

comment:1 Changed 5 years ago by dmethvin

  • need changed from Review to Test Case

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

comment:2 Changed 5 years ago by ckosti

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.

comment:3 Changed 5 years ago by reiern70

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 5 years ago by reiern70

reproduces the problem with AJAX updates and offset function

comment:4 Changed 5 years ago by reiern70

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

comment:5 Changed 5 years ago by RSparkyC

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?

comment:6 Changed 5 years ago by Rasetti

I'm having the same problem, using 1.4.2. Any chances of fixing it for the next release?

comment:7 Changed 5 years ago by pete

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");

  1. 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).

comment:8 Changed 5 years ago by jharte

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!

comment:9 in reply to: ↑ description Changed 5 years ago by thephatmann

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.

comment:10 Changed 5 years ago by dmethvin

  • Component changed from unfiled to dimensions

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.

comment:11 follow-up: ↓ 12 Changed 5 years ago by 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 }
};

comment:12 in reply to: ↑ 11 Changed 5 years ago by slenzi

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

Replying to 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 }
};

comment:13 Changed 4 years ago by thephatmann

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?

comment:14 Changed 4 years ago by john

  • Status changed from new to closed
  • Resolution set to fixed
  • Version changed from 1.3.2 to 1.4.2
  • Component changed from dimensions to offset
  • Milestone changed from 1.4 to 1.4.3
Note: See TracTickets for help on using tickets.