小编典典

将html放入iframe(使用javascript)

html

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

换句话说,假设我有一个ID为空的iframe,

如何在其中插入html?

我正在使用jquery,如果这样做更容易。


阅读 543

收藏
2020-05-10

共1个答案

小编典典

您也可以不用jQuery而做到:

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标签。

2020-05-10