简体   繁体   中英

Cross Domain postMessage Issue

I have a Main WebSite that calls an appi from another site, so Cross Domain arises as an issue. I´m trying with the method window.postMessage but it seems not working for me.

//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;
        }
    },
}

Problem is no alert whatsoever. Any guideline about this process, what am I missing? PS. I´m awared about the issues with window.addEventListener and Cross Browsing with IE and some old Opera browsers, but first I just need to get a simple ´Hello World´ using firefox, but so far with no success. Greetings.

Fact : Our web browsers does not allow to pass parameters over cross domain web api/wcf calls.

I faced this issue with web api.

Solution : Solution that worked for me was, I modified my web api to allow parameters to pass over cross domain. I used step by step instructions from this post: http://www.asp.net/web-api/overview/security/enabling-cross-origin-requests-in-web-api

If it doesn't work, try update your ASP.Net Web API package through nuget in addition.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM