avioing
avioing

Reputation: 650

IE 8 jquery error when using jquery + rails ujs driver + google maps v3. workaround?

tested with jquery 1.4.4 and 1.5.1, confirmed problem with both

when using jquery + rails ujs driver (from github) + google maps v3, clicking on a map marker causes IE error "Fail". when using a full, CDN-hosted jquery v 1.5.1, IE debugger points at line 2838 (please note that the problem does also occur with jquery.min.js, or version 1.4.4).

confirmed that it is the ujs driver which triggers this error. when the driver is removed, clicking markers does not result in error.

simple live example is available here: http://avioing.com/maps/marker-simple.html. this page is an exact copy of google's example page http://code.google.com/apis/maps/documentation/javascript/examples/marker-simple.html. i only added script calls to load jquery and the most recent ujs driver. you should be able to reproduce the error by clicking on the map marker.

the sample page works fine in FF and Chrome, and the error occurs only in IE

please also see http://avioing.com/maps/marker-simple_no_ujs.html and http://avioing.com/maps/marker-simple_no_marker.html, neither of which exhibits this problem.

does anyone know of a workaround?

Upvotes: 2

Views: 1236

Answers (2)

avioing
avioing

Reputation: 650

@Mark pointed me in the right direction, and I found the solution.

This is a known issue reported here http://bugs.jquery.com/ticket/7071, and there is a solution by the folks on the jquery team. There is a patch sitting in the jquery 1.4.4 bugfix branch (see discussion here https://github.com/jquery/jquery/pull/13 ), but it has not yet been pulled into either the 1.4.4 update or the 1.5.1 update.

From what I can see, there are 4 instances of "var elem = e.target, type = elem.type" in jquery (src/events.js) which need to be replaced. You can "git clone" the branch and build the patched jquery yourself, or patch your copy, or download one of the two I have already patched (absolutely no warranties, yada, yada…): https://gist.github.com/861689. So far, both appear to fix the specific problem which I described in my question.

Upvotes: 2

Mark Schultheiss
Mark Schultheiss

Reputation: 34197

This issue reminds me of a similar issue with IE and VML as noted here: http://bugs.jquery.com/ticket/7071 where, when IE encounters an element and you try to access an attribute of that element (elem.type in the jQuery code), it fails and further access attempts to that element are not met with success.

EDIT: WORK AROUND FOR YOUR ISSUE:

The line cited by you is: 2838 in jquery 1.5.1

var elem = e.target,
    type = elem.type;

you need to trap the error with something like so: (hack the jquery source)

    var testType = 'unknown';
    try { testType = elem.type; } catch (e) { /* kill IE exceptions on unknown type nodes */ }
    if (testType !== 'unknown') { 
    var elem = e.target,
        type = elem.type;
};

WARNING: You might run into more places with similar issues so test well.

Just to make it clear this is NOT the most efficient/best way to do this but does make it patently obvious what you/I am doing to work around this.

Upvotes: 2

Related Questions