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

查看:217
本文介绍了把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和插入HTML的头标签。

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

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

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