使用 jquery 时出现 IE 8 jquery 错误 + Rails ujs 驱动程序 +谷歌地图 v3.解决方法?

发布于 2024-10-20 17:01:47 字数 1038 浏览 1 评论 0原文

使用 jquery 1.4.4 和 1.5.1 进行测试,确认使用 jquery + Rails ujs 驱动程序(来自 github)+ google 地图 v3 时都存在问题

,单击地图标记会导致 IE 错误“失败”。当使用完整的、CDN 托管的 jquery v 1.5.1 时,IE 调试器指向第 2838 行(请注意,jquery.min.js 或版本 1.4.4 也会出现该问题)。

确认是ujs驱动触发了这个错误。删除驱动程序后,单击标记不会导致错误。

简单的实例可以在这里找到: http://avioing.com/maps/marker-simple.html< /a>.此页面是 Google 示例页面 http:// /code.google.com/apis/maps/documentation/javascript/examples/marker-simple.html。我只添加了脚本调用来加载 jquery 和最新的 ujs 驱动程序。您应该能够通过单击地图标记来重现该错误。

示例页面在 FF 和 Chrome 中工作正常,错误仅发生在 IE 中,

另请参阅 http:// /avioing.com/maps/marker-simple_no_ujs.htmlhttp://avioing.com/maps/marker-simple_no_marker.html,两者都不是表现出这个问题。

有人知道解决方法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情定在深秋 2024-10-27 17:01:47

这个问题让我想起了 IE 和 VML 的类似问题,如下所示: http://bugs.jquery .com/ticket/7071 其中,当 IE 遇到一个元素并且您尝试访问该元素的属性(jQuery 代码中的 elem.type)时,它会失败,并且不会满足对该元素的进一步访问尝试成功。

编辑:解决您的问题:

您引用的行是:jquery 1.5.1 中的 2838

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

您需要使用类似这样的内容来捕获错误:(破解 jquery 源)

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

警告:您可能会遇到更多类似问题的地方,因此测试好。

只是为了说明这一点,这不是最有效/最好的方法,但确实使您/我正在做什么来解决这个问题变得显而易见。

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.

亣腦蒛氧 2024-10-27 17:01:47

@Mark 为我指明了正确的方向,我找到了解决方案。

这是此处报告的已知问题 http://bugs.jquery.com/ticket/7071, jquery 团队的人员提供了一个解决方案。 jquery 1.4.4 bugfix 分支中有一个补丁(请参阅此处的讨论https://github。 com/jquery/jquery/pull/13 ),但尚未被拉入 1.4.4 更新或 1.5.1 更新。

据我所见,jquery (src/events.js) 中有 4 个“var elem = e.target, type = elem.type”实例需要替换。你可以“git克隆”分支并自己构建修补过的jquery,或者修补你的副本,或者下载我已经修补过的两个之一(绝对没有保证,yada,yada…):https://gist.github.com/861689。到目前为止,两者似乎都解决了我在问题中描述的具体问题。

@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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文