IE7“操作中止”即使用FastInit? [英] IE7 "Operation Aborted" even with FastInit?

查看:181
本文介绍了IE7“操作中止”即使用FastInit?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理的一段JavaScript代码导致了IE中令人讨厌的操作中止消息。我很清楚,在加载DOM之后,您不能修改DOM。确定的JavaScript代码引起错误的行是向身体附加一个新的div标签的那一行。然而,线路所在的功能是通过FastInit.addOnLoad调用的!我以为这意味着在DOM准备好之后会调用这个函数。有没有更好的解决这个问题,使用FastInit?

A piece of javascript code I'm working on is causing the nasty "Operation Aborted" message in IE. I am well aware that you cannot modify the DOM until after it has loaded. Sure enough the line of javascript code causing the error is the one which appends a new div tag to the body. However the function which the line is located within is called via FastInit.addOnLoad! I thought this meant the function would be called after the DOM was ready. Is there a better solution to this problem that using FastInit?

推荐答案

N.B。 SO正在玩格式化的愚蠢的bug;不幸的是,

N.B. SO is playing silly buggers with the formatting; sorry about that.

当您尝试修改脚本元素的祖父母元素时,会出现中止操作错误。所以,例如,以下代码将导致它,因为该脚本尝试从一个子div修改body,这意味着它正在尝试修改其祖父母元素:

The "Operation Aborted" error occurs when you try to modify the grandparent element of the script element. So, for example, the following code will cause it because the script is attempting to modify the body from a child div, meaning it is trying to modify its grandparent element:

<body>
    <div id="foo">
        <script type="text/javascript">
        var newThing = document.createElement("div");
        /* ### The next line will cause the error ### */
        document.body.appendChild(newThing);
        <script>
    </div>
</body>

相同的代码更改为:

<body>
    <div id="foo">
    </div>
    <script type="text/javascript">
    var newThing = document.createElement("div");
    /* ### The next line will NOT cause an error ### */
    document.body.appendChild(newThing);
    <script>
</body>

导致错误,因为脚本正在修改其父,它可以处理。

would not cause the error, as the script is now modifying its parent, which IE can handle.

这种情况最常见的原因是您未能关闭 div (或其他元素);找到缺少的关闭标签,你会修复它。或者,如果您的脚本实际上 在另一个元素中,则将其移出,以便它是正文的孩子。

The most common reason for this happening is that you have failed to close a div (or other element) further up the page; find the missing close tag and you'll fix it. Alternatively, if your script actually is inside another element, move it out so it is a child of the body.

这篇关于IE7“操作中止”即使用FastInit?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆