写父母的> iFrame的> iFrame内容 [英] Write Parent's > iFrame's > iFrame Content

查看:108
本文介绍了写父母的> iFrame的> iFrame内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Html布局与此类似:



父页> iFrame



<我想写动态iframe&内容所以布局应该类似于:



父> iFrame>写新的iFrame&这是内容



我可以使用此代码为子iframe编写html内容



父页> iFrame> Hello World!

  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'; //重复你需要的任何其他属性
ifrm.document.body.appendChild(childfrm); //或者使用insertBefore将它添加到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();

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


I have Html Layout Similar to this :

Parent Page > iFrame

I want to write dynamic iframe & content so the layout should look similar to this :

Parent > iFrame > Write New iFrame & It's Content

I'm able to write html content for child iframe using this code

Parent Page > iFrame > Hello World!

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();

but How can I write same content inside :

Parent Page > iFrame > iFrame > Hello World ?

All iFrames are on same Domain.

解决方案

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();

(This is untested, but I think it'll work)

这篇关于写父母的&gt; iFrame的&gt; iFrame内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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