oyvindkinsey / easyXDM

A javascript library providing cross-browser, cross-site messaging/method invocation.

Home Page:http://easyxdm.net

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

check 'callerWindow.contentWindow.sendMessage' in NameTransport

j1anb1n opened this issue · comments

In my project, I need to move the script in name.html to another javascript file like name.js.

so, sometime it will fail while call callerWindow.contentWindow.sendMessage.

my resolution is:

easyXDM.stack.NameTransport = function(config){
    ...
    function _onMessage(message){
        (function test(){
            if (typeof callerWindow.contentWindow.sendMessage == "function") {
                pub.up.incoming(message, remoteOrigin);
            }
            else {
                setTimeout(test, 50);
            }
        }());
    }
    ...

Why would this fail? If the script is loaded synchronously (eg a script tag) then this should be loaded prior to the page firing the load event, no?

But I don't get how you expect this to work, _onMessage is called by the code in the script you are mentioning, so that test will always return true..

<!doctype html>
<html>
    <head>
        <script type="text/javascript" charset="utf-8">
        var d = new Date;                        
        d = parseInt((+d-(+d%72E5))/1E3); // expire in two hours       
        var str = unescape("%3Cscript src='http://sta.xxx.com/cgi.php?file=js/util/easyxdm/name.__"+d+"__.js' type='text/javascript'%3E%3C/script%3E");
        document.write(str);
        </script>
    </head>
    <body>
    </body>
</html>

This is my name.html.
I think it is not need to add my code into your version.

Sorry for my poor English...

But why would you load this script in this way?
The point of name.html is that it should be a single, fast, highly-cacheable resource, and with the name.html as provded by the project, this issue you are having will not be a problem.