使用JavaScript中的动态内容填充IFRAME [英] Filling an IFRAME with dynamic content from JavaScript

查看:854
本文介绍了使用JavaScript中的动态内容填充IFRAME的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个IFRAME,应该填充JavaScript中的内容。如果内容在服务器上,我所要做的就是:

I have an IFRAME that should be filled with content from JavaScript. Had the content be on the server all I had to do is:

    function onIFrameFill() {
         myIframe.location.href = "HelloWorld.html";
     }

但我所拥有的内容是在客户端上生成的HTML页面,表示为一个字符串(我对它没有多大影响)。如何以编程方式填充我的iframe内容?

But the content I have is a HTML page generated on the client and represented as a string (I have not much influence on it). How can I populate the content of the my iframe programatically?

推荐答案

我想你正在寻找类似的东西:

I think you're looking for something like:

var iframeDoc = myIframe.contentWindow.document;
iframeDoc.open();
iframeDoc.write('hello world');
iframeDoc.close();

这篇关于使用JavaScript中的动态内容填充IFRAME的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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