IE9 在 iframe 中加载脚本时抛出异常.为什么? [英] IE9 throws exceptions when loading scripts in iframe. Why?

查看:20
本文介绍了IE9 在 iframe 中加载脚本时抛出异常.为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

前提:

我有一个带有 iframe 的 aspx 页面.此 iframe 指向同一站点(它是混合站点,标准 ASP.NET 和 ASP.NET MVC)上由 MVC 处理的 url.MVC 呈现的结果页面包含大量脚本引用.

I have an aspx-page with iframe inside. This iframe points to the url handled by MVC on the same site (it's hybrid site, both standard ASP.NET and ASP.NET MVC). The resulting page rendered by MVC contains a lot of scripts references.

问题:

IE9 会在 iframe 中加载的每个脚本上引发异常.这些异常与此类似:

IE9 throws an exception on every single script it load in iframe. These exceptions are similar to this one:

Error: 'Function' is undefined

也就是说,它说每个窗口所拥有的最基本的东西都以某种方式缺失了.单击所有这些弹出窗口后,该页面将按设计运行!
如果我直接从浏览器中的 <iframe/> src 属性加载 URL,一切都会按预期进行.
如果我在另一个浏览器中打开页面(我尝试过 Opera、Firefox),一切都按预期工作 - 没有错误.

That is, it says that the most basic things every window has is somehow absent. Once you clicked through all of these popups, the page just works as designed!
If I load a URL from <iframe /> src attribute in the browser directly, everything works as expected.
If I open the page in another browser (I tried Opera, Firefox), everything works as expected -- no errors.

那么,IE9 想要什么?

So, what IE9 wants?

推荐答案

此 msdn 页面 关于此错误(或功能).

There is this msdn page about this bug (or feature).

当您在 DOM 中移动 iframe 元素时,您会遇到此类错误.在这种情况下,IE 9 垃圾收集 iframe(导致您未定义的错误)并在另一个位置重新加载它.

You get these kinds of errors when you move the iframe element around in DOM. In such cases, IE 9 garbage collects the iframe (causing your undefined bug) and reloads it at another position.

一般来说,你应该创建元素,只设置它的src属性一次,然后把它放在DOM树的某个位置一次.它与在 iframe 本身中运行的代码无关.

In general, you should create the element, set its src attribute only once and then put it somewhere in the DOM tree once. It has nothing to do with the code which runs in the iframe itself.

这篇关于IE9 在 iframe 中加载脚本时抛出异常.为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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