もちろん、以下のすべては、IFrame が同じドメイン (同じオリジン ポリシー) から読み込まれることを前提としています。しかし、あなたの例を考えると、それは事実のようです。別のドメインから IFrame を読み込んでいる場合、ブラウザは IFrame とのほとんどのやり取りを妨げます (変更できるのはハッシュのみです...)。
したがって、最初に、 (Ext の Element ではなく) IFrame DOM 要素への参照を取得する必要があります。document
次に、この方法で IFrame のオブジェクトへの参照を取得できます(こちらから盗みました)。
// iframe is the DOM element
var iframeWindow = (iframe.contentWindow) ? iframe.contentWindow : (iframe.contentDocument.document) ? iframe.contentDocument.document : iframe.contentDocument,
doc = iframeWindow.document;
Ext.get(doc)
次に、またはを使用Ext.fly(doc)
して、返されたラッパー Ext Element を操作できます。
「iframe コンポーネント」を定義し、そのロード イベントを待機し、子を追加する完全な例を次に示します。
items: [{
xtype: "component"
// using autoEl instead of html property, so the iframe will be the `el`
// property of the component
,autoEl: {
tag : "iframe"
,src: "/page/object/"
,frameborder: 0
}
// listening on the iframe's load event
,listeners: {
el: {
load: function() {
var iframe = this.dom,
iframeWindow = (iframe.contentWindow) ? iframe.contentWindow : (iframe.contentDocument.document) ? iframe.contentDocument.document : iframe.contentDocument,
docEl = Ext.fly(iframeWindow.document),
body = docEl.down('body'); // instance of Ext.dom.Element
// now you can do what you want with the iframe body!
body.createChild({tag: 'div', html: 'I am bold', style: 'font-weight: bold;'})
}
}
}
}]