2016-09-19 19 views
0

我使用EasyXDM來處理跨域通信,以便父級知道孩子的大小和孩子的位置。我有大小工作。問題是當我在iframe內導航時,我想將位置推回到父級。簡易XDM - IFrame導航斷開套接字

問題是,當我改變套接字無法再次創建的頁面時,給我VM87 Core.js:324未捕獲錯誤:url未定義或爲空

其他人碰到過嗎?

父(消費者):

<script language="javascript"> 
    (function() { 
    // CTOR has side effect of creating globals for socket 
     var socket = new easyXDM.Socket({ 
      remote: "@(Model.Url)" + document.location.hash, 
      container: $("#pluginFrame")[0], 
      onMessage: function (message, origin) { 
       var messageAsObject = JSON.parse(message); 

       if (messageAsObject.height) { 
        $("#pluginFrame iframe").height(messageAsObject.height); 
       } 

       if (messageAsObject.path) { 
        document.location.hash = messageAsObject.path; 
       } 
      }, 
      onReady: function() { 
       console.log("Shell Socket Ready"); 
       $("#pluginFrame iframe").width("100%"); 
      } 
     }); 
    })(); 
</script> 

兒童(製片人)剃刀布局

<script language="javascript"> 
    (function() { 
     debugger; 
     var socket = new easyXDM.Socket({ 
      onReady: function() { 
       console.log("eBox Ready"); 

       socket.postMessage(JSON.stringify({ 
        height: $(".body-content").outerHeight(), 
        path: document.location.pathname 
       })); 
      } 
     }); 

     $("body-content") 
      .on("change", 
       function() { 
        socket.postMessage(JSON.stringify({ 
         height: $(".body-content").outerHeight() 
        })); 
       }); 

     $(document.location.pathname) 
      .on("change", 
       function() { 
        socket.postMessage(JSON.stringify({ 
         path: document.location.pathname 
        })); 
       }); 

     socket.postMessage(JSON.stringify({ 
      path: document.location.pathname 
     })); 
    })(); 
</script> 

回答

0

從一切我見過有沒有可能的方式做我後。看來,我最終試圖解決的問題的唯一解決方案是將路由推送到父級的位置散列,這是使用這裏提到的雙重iframe方法。

Resizing an iframe based on content