Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/400.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 写入父项';s>;iFrame';s>;iFrame内容_Javascript_Iframe - Fatal编程技术网

Javascript 写入父项';s>;iFrame';s>;iFrame内容

Javascript 写入父项';s>;iFrame';s>;iFrame内容,javascript,iframe,Javascript,Iframe,我的Html布局与此类似: 父页面>iFrame 我想编写动态iframe和内容,因此布局应类似于以下内容: Parent>iFrame>编写新的iFrame及其内容 我能够使用以下代码为子iframe编写html内容 父页面>iFrame>你好,世界 var ifrm = document.getElementById('myIframe'); ifrm = (ifrm.contentWindow) ? ifrm.contentWindow : (ifrm.contentDocument.do

我的Html布局与此类似:

父页面>iFrame

我想编写动态iframe和内容,因此布局应类似于以下内容:

Parent>iFrame>编写新的iFrame及其内容

我能够使用以下代码为子iframe编写html内容

父页面>iFrame>你好,世界

var ifrm = document.getElementById('myIframe');
ifrm = (ifrm.contentWindow) ? ifrm.contentWindow : (ifrm.contentDocument.document) ? ifrm.contentDocument.document : ifrm.contentDocument;
ifrm.document.open();
ifrm.document.write('Hello World!');
ifrm.document.close();
但我怎样才能在里面写同样的内容:

父页面>iFrame>iFrame>Hello World?

所有iFrame都在同一个域上

var ifrm = document.getElementById('myIframe');
ifrm = (ifrm.contentWindow) ? ifrm.contentWindow : (ifrm.contentDocument.document) ? ifrm.contentDocument.document : ifrm.contentDocument;
var childfrm = ifrm.document.createElement('iframe');
childfrm.id = 'myChildIframe'; // repeat for any other properties you need
ifrm.document.body.appendChild(childfrm); // or use insertBefore to add it somewhere specific within the DOM
var childwin = (childfrm.contentWindow) ? childfrm.contentWindow : (childfrm.contentDocument.document) ? childfrm.contentDocument.document : childfrm.contentDocument;
childwin.document.open();
childwin.document.write('Hello World!');
childwin.document.close();

(这是未经测试的,但我认为它会起作用)

您使用jQuery进行了标记。JQUERY在哪里?ifrm.document.write(“”);然后取出它并将文档写入it@galchen我想用内容编写动态iframe,这样src属性就不会这样工作了