JavaScript的code在iframe中在IE9不工作 [英] Javascript code in iframes in IE9 not working

查看:120
本文介绍了JavaScript的code在iframe中在IE9不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ASP.NET至极一个非常完整的网站使用iframe。我在努力改变,我们一直在使用,以显示对话框使用jQuery UI的对话框的旧的控制。我也是在IE9确保一切正常。

事实是:我在iframe中所示的页面已经剧本没有在IE9工作。为什么?因为对象,数组和字符串是不确定的。可能有一些其他的问题,我已经看到了只有这个人。

有没有机会(因为很多原因)停止使用一些对话框内部框架。而我宁可不使用元标签强制IE8保持兼容。有谁知道什么办法来解决这个uggly错误的IE9?

谢谢,迭戈

修改

下面有一些信息可能是helfull:

jQuery的code在插件的iframe我做出决定的配置jQuery用户界面对话框:

  options.content = $(< IFRAME>中)
    .attr(src用户,options.intSrcIframe)
    .attr(FRAMEBORDER,0)
    .attr(滚动,options.intIframeScrolling)
    的CSS(背景色,options.intBgColorIframe)
    .attr(高度,100%)
    .attr(宽度,100%);_this.html(options.content);


解决方案

请注意:的这里有来自IE9的一些文档,可以帮助理解。感谢@Ben雨田分享它。


几乎一个星期后的一天快要疯了一天后,我发现它了。

与IE9的问题是没有用专门的内部框架的JavaScript code。甚至不是通过JavaScript或任何图书馆加到内部框架的JavaScript(我有很多JS库和插件,可以拧IE9的)。

问题是,当你移动iframe或通过DOM一个祖先。 IE9将excecute的code在iframe中加载多次,你出招的页面。每次(除了最后一个)都会有对象,字符串,数组和其他不确定的(和其他错误太)。

例如:

  VAR IFRAME = $(< IFRAME>中)。ATTR(SRC,www.example.com),ATTR(ID,myIframe) ;
iframe.appendTo(身体);
$(#myIframe)appendTo(形式:当量(0))。

中的JavaScript $ C $中的cwww.example.com将一旦与上述的误差没有错误执行,并且然后一旦

通过以​​下code中的code将excecuted只是一次正常:

  VAR IFRAME = $(< IFRAME>中)。ATTR(SRC,www.example.com),ATTR(ID,myIframe) ;
iframe.appendTo(形式:当量(0));

我希望这可以帮助别人,以避免这种痛苦的屁股,

圣迭戈

I've a very complete site in ASP.NET wich uses iframes. I'm working to change an old control we'd been using to show dialogs to use jQuery UI dialogs. I'm also making sure everything works well in IE9.

The fact is: the script I've in the pages shown in iframes is not working in IE9. Why? Because Object, Array and String are undefined. There may be some others issues, I've seen only this ones.

There is no chance (because a lot of reasons) to stop using iframes on some dialogs. And I'd rather not to use the meta tag to force IE8 Compability. Does anyone know any way to fix this uggly bug in IE9?

Thanks, Diego

Edit

Here there's some info that may be helfull:

jQuery code for the iframe in a plugin I've made to config jQuery UI dialog:

options.content = $("<iframe>")
    .attr("src", options.intSrcIframe)
    .attr("frameborder", 0)
    .attr("scrolling", options.intIframeScrolling)
    .css("background-color", options.intBgColorIframe)
    .attr("height", "100%")
    .attr("width", "100%");

_this.html(options.content);

解决方案

Note: here there is some documentation from IE9 that may help to understand. Thanks to @Ben Amada for sharing it.


After almost a week of going crazy day after day I found it out.

The problem with IE9 is no specifically with the javascript code in the iframes. Not even with the javascript in iframes added by javascript or any library (I have lots of js libraries and plugins that could be screwing IE9).

The problem is when you move the iframe or one ancestor through the DOM. IE9 will excecute the code in the page loaded in the iframe as many times as moves you make. Each time (but the last one) will have Object, String, Array and others undefined (and other bugs too).

Example:

var iframe = $("<iframe>").attr("src", "www.example.com").attr("id", "myIframe");
iframe.appendTo("body");
$("#myIframe").appendTo("form:eq(0)");

The javascript code in "www.example.com" will be executed once with the error described above and then once with no errors.

With the following code the code will be excecuted just once and correctly:

var iframe = $("<iframe>").attr("src", "www.example.com").attr("id", "myIframe");
iframe.appendTo("form:eq(0)");

I hope this helps someone to avoid this pain in the ass,

Diego

这篇关于JavaScript的code在iframe中在IE9不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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