在Firefox中使用JavaScript设置iframe的内容失败 [英] Setting content of iframe using javascript fails in firefox

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

问题描述

我尝试使用javascript设置iframe的内容。



我有html字符串。我在写: -

  var iframe = $('iframe')[0],
content = '< DIV>试验< / DIV>';
$(iframe).contents()。find('html')。html(content);

在谷歌浏览器中可以正常工作,但是在Firefox中显示内容的时间和消失。
请帮我解决它。

解决方案

我面临同样的问题。我看到iframe的加载函数在firefox中启动,但在chrome中没有启动。所以firefox在加载事件中重新加载iframe。



所以用你现有的代码试试这个:

<$ p $ (内容);
$(iframe).contents()。 b $ b})


I'm trying to set the content of a iframe using javascript.

I've the html string. And I'm writing:-

 var iframe = $('iframe')[0],
 content = '<div>test</div>';        
 $(iframe).contents().find('html').html(content);

It works fine in google chrome, but in firefox is shows the content for a moment and the disappears. Please help me to fix it.

解决方案

I faced the same problem. I saw the load function of iframe fires in firefox but not in chrome. So firefox reload the iframe again on load event.

So with your existing code try this:-

   $(iframe).load(function(e){
      $(iframe).contents().find('html').html(content);

    })

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

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