iframe内容在Firefox上消失了 [英] iframe content disappears on Firefox

查看:90
本文介绍了iframe内容在Firefox上消失了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用基本HTML填充空iframe,使用 $ iframe.contents()。find('body')。html(contentBody);

I am filling an empty iframe with basic HTML, using $iframe.contents().find('body').html(contentBody);

请参阅: http://jsfiddle.net/UjT2b/2/

这适用于Chrome。在Firefox上,我可以非常简单地看到里面的内容,但它突然消失了。当我使用Firebug在此行上设置断点,然后继续运行时,内容保持在内部。但如果我在线后设置断点,它就会消失。

This works well on Chrome. On Firefox, I can see very briefly the content inside, but then it suddenly disappears. When I set a breakpoint on this line with Firebug, then continue running, the content stays inside. But if I set a breakpoint on the line after, it goes away.

关于如何解决这个问题的任何线索?

Any clue on how to fix this?

推荐答案

我在尝试填充动态创建的iframe时遇到了类似的问题。使用iframe onload事件为我解决了这个问题。正如所见,onload解决方案不适用于除FF之外的其他浏览器,因此保留了标准方式。

I have encountered similar problem while attempting to fill dynamically created iframe. Using of iframe onload event solved the situation for me. As seen the onload solution does not work for other browsers than FF, hence the preserved standard way.

/**
 * Fills an iframe using data stored within textarea. Useful for creating email
 * template previews
 *
 * @param  {String} inputSelector
 * @param  {String} outputElemClasses
 * @return void
 */
function displayEmail(inputSelector, outputElemClasses)
{
    $(inputSelector).each(function(i) {
        var templateData = $(this).text();
        var $iframe = $('<iframe></iframe>');
        $iframe.addClass(outputElemClasses);
        $iframe.insertAfter(this);
        // non-firefox
        updateIframe($iframe, templateData);
        // firefox
        $iframe.load(function(e){
            updateIframe($iframe, templateData);
        })
    })
}


/**
 * Fills in target iframe using supplied data
 *
 * @param  {Object} $iframe
 * @param  {String} data
 * @return void
 */
function updateIframe($iframe, data)
{
    $iframe.contents().find('html').html(data);
}            

这篇关于iframe内容在Firefox上消失了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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