1

私はdjangoとextjsを使用しています。そのようなextjs iframeでhtmlページを作成します

items: [{
     html: '<iframe src="/page/object/" width="100%" height="100%"></iframe>'
 }],

でページをviews.pyレンダリングしますhtmliframe

return render(request, 'page.html', {
    'items': item
})

Ext.fly("")iframe の html ページに add something (createchild)を使用したいと考えています。

出来ますか?どうやって?

4

1 に答える 1

0

もちろん、以下のすべては、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;'})
            }
        }
    }
}]
于 2013-06-11T12:01:43.927 に答える