2014-03-03 69 views
2

我正在使用以下代碼在sencha觸摸標籤面板中插入iframe。我正在Iframe中加載已認證的頁面。此頁面包含用戶名和密碼字段。頁面登錄成功,但我想從iframe回覆到Sencha應用程序的登錄狀態的響應。Sencha Touch 2.3.1 Iframe

Ext.application({ 
    launch: function() 
    {     
     Ext.define('I', { 
      extend: 'Ext.Component', 
      xtype: 'iframecmp', 
      config: {      
       url  : null      
      },  
      initialize: function() { 
       console.log("Main"); 
       var me = this; 
       me.callParent(); 
       me.iframe = this.element.createChild({ 
        tag: 'iframe', 
        src: this.getUrl(), 
        style: 'width: 500px; height: 500px; align:middle;' 
       }); 

       me.relayEvents(me.iframe, '*'); 
      } 
     }); 



     Ext.create("Ext.tab.Panel", { 
      extend: "I", 
      tabBarPosition: 'bottom', 
      fullscreen: true, 
      items: [ 
       { 
        title: 'Sencha', 
        id: "main-frame", 
        name: "main-frame", 
        iconCls: 'action', 
        xtype: 'iframecmp', 
        url: 'http://testcop.bridgealliance.com/TSM_dev_Insphere', 
        style: 'width: 500px; height: 500px; left: 100px;', 
        scroll: 'vertical' 
       }, 
       { 
        title: 'Sencha', 
        id: "main-frame2", 
        name: "main-frame2", 
        iconCls: 'action', 
        xtype: 'container', 
        html: '<iframe src="http://localhost/phpinfo.php"></iframe>', 
        style: 'width: 50%; height: 50%; left: 10%; top: 10%;' 
       } 

      ] 
     }); 
    } 
}); // application() 

回答

0

如果這兩個窗口在同一個領域,你可以創建你的父母的方法回調(),並與

父窗口調用它的孩子:

window.callBack = function(msg) { console.log(msg); } 

兒童iFrame:

​​

如果孩子iFrame在不同的域中,那麼瀏覽器將禁止此操作,您需要使用window.postMessage()才能從子窗口發送偶數,並且需要使用window.addListener("message", function(msg) {})來收聽父母中的這些事件。

這裏有一個很好的教程,說明如何使用它......