将 html 放在 iframe 中(使用 javascript) [英] putting html inside an iframe (using javascript)

查看:28
本文介绍了将 html 放在 iframe 中(使用 javascript)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以创建一个空的 iframe 作为占位符,以便稍后将 html 插入其中吗?

Can I create an empty iframe as a placeholder to later insert html into it?

换句话说,假设我有一个带有 id 的空 iframe,

In otherwords, suppose I have an empty iframe with an id,

如何在其中插入 html?

How do I insert html in it?

我正在使用 jquery,如果这样方便的话.

I'm using jquery, if that makes it easier.

推荐答案

你也可以不用 jQuery:

You can do it without jQuery also:

var iframe = document.getElementById('iframeID');
iframe = iframe.contentWindow || ( iframe.contentDocument.document || iframe.contentDocument);

iframe.document.open();
iframe.document.write('Hello World!');
iframe.document.close();

jQuery 的 html 从插入的 HTML 中去除 body、html 和 head 标签.

jQuery's html strips body, html and head tags from the inserted HTML.

这篇关于将 html 放在 iframe 中(使用 javascript)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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