无法仅在Chrome中写入FF或IE中的iframe [英] Can't write to iframe in FF or IE, only Chrome

查看:123
本文介绍了无法仅在Chrome中写入FF或IE中的iframe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您在CHrome中运行此jsfiddle,它将起作用,但在IE和FF上它将失败: http://jsfiddle.net/LbFPu/2/

If you run this jsfiddle in CHrome, it will work, but on IE and FF it fails: http://jsfiddle.net/LbFPu/2/

我想这与每个引擎如何写入DOM有关吗?有什么方法可以等待以前的内容被写入吗?例如:

I imagine it has something to do on how each engine writes into the DOM? Is there any way to wait for previous content to be written? Ex:

function firstMe(){
    $('body').append('<div id="first"></div>');
    // many other new elements appended
}

function thenMe(){
    $('#first').append('etc');
    // many of the recently appended elements being referenced
}

按顺序调用时,我想它可以在CHrome中正常工作,但不能在IE& FF.从jsfiddle结果来看.

When called in order, I imagine it would work properly in CHrome, but not in IE & FF. Judging by the jsfiddle result.

有人曾经处理过吗?

推荐答案

那只是因为您正尝试写入尚未加载的iframe,因此chrome看起来更快:

That's just because you're trying to write to an iframe that's not loaded yet, seems chrome is faster :

$('body').append('<iframe id="upload"></iframe>');
var form = $('<form enctype="multipart/form-data" id="image_upload" action="index.php">'
     + '<input type="file" accept="image/*" multiple name="img[]" id="image" />'
     + '<br>'
     + '<input type="submit" value="Upload images" class="upload" />'
     + '</form>');

$('#upload').on('load', function() {
    $(this).contents().find('body').append(form);
});

FIDDLE

这篇关于无法仅在Chrome中写入FF或IE中的iframe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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