2014-09-20 159 views
1

我有一個主要網站從另一個網站調用appi,因此跨域出現問題。我正在嘗試使用window.postMessage方法,但它似乎不適合我。跨域postMessage問題

//This is the appi that sends the message. 
$(document).ready(function() { 
    solution01.ini(); 

}); 
var solution01= { 


    ini:function(){ 
    window.parent.postMessage('Hello World', 'http://webappi:0000'); 

}, 
} 

//this is in the Main Page that have the IFrame that calls the appi above. 

$(document).ready(function() { 


mainSolution.ini(); 
}); 

var mainSolution = { 


    ini:function(){ 
     window.addEventListener('message', mainSolution.handleResponse, false); 
    }, 

    handleResponse:function(evt) { 

     if (evt.origin === 'http://webappi:0000') 
     { 
      alert("I'm happy to say: "+evt.data); 
     }else{ 

      return; 
     } 
    }, 
} 

問題沒有任何提醒。關於這個過程的任何指南,我錯過了什麼? PS。我用IE瀏覽器和一些老的Opera瀏覽器瞭解了window.addEventListener和Cross Browsing的問題,但首先我需要使用firefox獲得一個簡單的'Hello World',但目前爲止還沒有成功。問候。

回答