IE8在向div插入数据时强制兼容模式

发布于 2024-09-17 07:38:25 字数 1653 浏览 12 评论 0原文

我一整天都在与 IE8 的兼容模式作斗争,我准备向它扔一块砖头。

我有一些代码,它使用 jquery 1.2(是的,它很旧 - 无法更改),在我们的网络应用程序中搜索一些记录。可以单击搜索结果来查看记录的内容(通过使用 .animate(),它会在行下打开一个空间,并在下面创建另一个 TR,并插入来自 json feed 的 HTML 数据)。

在 IE8 中,单击结果查看内容会强制其以兼容模式重新加载,在所有其他浏览器(IE7、FF3.0+、Chrome、Safari)中都可以正常工作。我一直在尝试使用 IE8 的开发人员工具栏来调试和追踪发生这种情况的原因,但我无法找到任何错误或任何可能导致此问题的证据。

显示预览的代码:

// Code that binds a click to open the result preview:
var _tr = $('<tr class="outline" id=' + val.assessment.assessmentId + '></tr>').bind("click", msi.reuseAssessment.preview);

...

// in msi.reuseAssessment.preview()
var url = "/direct/msi-assessment/" + assessmentId + "/assessmentHtml.json?no-cache=true";
jQuery.ajax({
    type: "GET",
    url: url,
    dataType: "json",
    success: function(d, textStatus){
        var _content = d.assessmentHtml;
        var _preview = $("<tr id=" + assessmentId + "></tr>");

        // loadContent 
        _tr.after(_preview.animate({
            height: 50
        }, 500, 0, function() {
            msi.reuseAssessment.drawPreview(this, _content); // Puts the content from the json into a td
        }));
    },
    error: function(xmlHttpReq, status, errorThrown) {
        // display error msg
    }
});

使用 IE8 的开发人员工具单步执行代码,它会被传递到此处并进入 jQuery 代码的某个位置,此时它会以兼容模式刷新。我已经验证了 JSON、w3c 提供的 HTML 代码,一切都很好,我真的不知道发生了什么。

有谁知道我如何更好地找出导致此问题的原因,或者我应该在这些页面上强制使用 IE7 模式?

编辑:搜索是在屏幕顶部出现的 ajax“弹出窗口”中执行的。它的模板(基本 HTML)从单独的 HTML 文件加载,并注入到原始页面底部的 div 中。这意味着会有嵌套的 HTML 文件(带有 标签等)。这也会影响吗?
编辑 3:删除这些重复的标签并没有解决问题。

编辑2:仍然没有解决这个问题。这是否只是 IE8 无法正常显示并将其归因于浏览器怪癖的原因之一?我真的很感激对此的一些帮助。

I've been fighting against IE8's compatibility mode all day and I'm about to chuck a brick at it.

I have some code, which uses jquery 1.2 (yes it's old - can't change that), to search for some records in our web app. The results of the search can be clicked on to view the contents of the record (by using .animate() it opens a space under the row and creates another TR underneath and inserts HTML data from a json feed).

In IE8, clicking on a result to view the content forces it to reload in compatibility mode, where it works fine in all other browsers (IE7, FF3.0+, Chrome, Safari). I've been trying to use IE8's developer toolbar to debug and track down why this is happening but I've not been able to find any error or any evidence of what might be causing it.

Code that shows preview:

// Code that binds a click to open the result preview:
var _tr = $('<tr class="outline" id=' + val.assessment.assessmentId + '></tr>').bind("click", msi.reuseAssessment.preview);

...

// in msi.reuseAssessment.preview()
var url = "/direct/msi-assessment/" + assessmentId + "/assessmentHtml.json?no-cache=true";
jQuery.ajax({
    type: "GET",
    url: url,
    dataType: "json",
    success: function(d, textStatus){
        var _content = d.assessmentHtml;
        var _preview = $("<tr id=" + assessmentId + "></tr>");

        // loadContent 
        _tr.after(_preview.animate({
            height: 50
        }, 500, 0, function() {
            msi.reuseAssessment.drawPreview(this, _content); // Puts the content from the json into a td
        }));
    },
    error: function(xmlHttpReq, status, errorThrown) {
        // display error msg
    }
});

Stepping through the code using IE8's developer tools, it gets passed here and into somewhere into jQuery's code and that's when it refreshes in compatibility mode. I've validated the JSON, the HTML code that comes out with w3c and it's all fine, I'm really at a loss as to what's happening.

Does anyone know how I might better track down what's causing it, or should I just force IE7 mode on these pages?

Edit: The search is performed in an ajax 'popup' that appears over the top of the screen. It's template (base HTML) is loaded from a separate HTML file, and injected into a div at the bottom of the original page. This means there would be nested HTML files (with <html></html> tags etc). Would this affect it also?
Edit 3: removing these duplicate tags did not fix the problem.

Edit 2: Still haven't solved this. Is it just one of those things that IE8 won't display properly and put it down to browser quirk? I would really appreciate some help on this.

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

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

发布评论

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

评论(3

南汐寒笙箫 2024-09-24 07:38:26

在一位同事也做了一些搜索之后,我们在这里找到了这个,它在哪里已确认 max-height 在 IE8 中导致硬断言,确认这确实是 IE8 中的一个错误,正如 EricLaw 发布的那样。

我们使用 max-height 作为要插入内容的 div 的样式,进而导致硬断言。上面链接的问题可以为遇到此问题的其他人提供解决方法。

After a colleague did some searching as well, we found this here on SO, where it's been confirmed that max-height is causing a hard assert in IE8, confirming that it is, indeed, a bug in IE8 as EricLaw posted.

We were using max-height for the style of the div we were inserting the content into, and in turn, causing the hard assert. The above linked question has a work around for anyone else encountering this problem.

守望孤独 2024-09-24 07:38:25

强制其以兼容模式重新加载是否意味着您会收到一个弹出气球通知,内容如下:“Internet Explorer 遇到此页面问题并已以兼容模式加载它”?

如果是这样,则意味着您遇到了 IE 中的错误。称为“硬断言”,它意味着布局引擎崩溃了(不是 AV 或任何令人兴奋的东西,它只是进入了不可恢复的状态),因此 IE 尝试通过使用较旧的布局引擎。

如果问题在 IE9 中仍然出现,请在 http://connect.microsoft.com/ie

谢谢!

By forces it to reload in compatibility mode do you mean that you get a flyout balloon notification that says something like: "Internet Explorer encountered a problem with this page and has loaded it in compatibility mode"?

If so, that means you've hit a bug in IE. Called a "Hard assert" it means that the layout engine crashed (not an AV or anything exciting, it just got into an unrecoverable state) and thus IE tries to provide the user with some content by using the older layout engine.

If the problem still occurs in IE9, please file a bug at http://connect.microsoft.com/ie

thanks!

笨笨の傻瓜 2024-09-24 07:38:25

您是否确保您的 DOCTYPE 和 X-UA-Compatible 正确

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

并将其添加到 之后

<meta http-equiv="X-UA-Compatible" content="IE=8">

Have you ensured your DOCTYPE and X-UA-Compatible are correct

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

And add this just after the <head>

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