Is cross-origin postMessage broken in IE10?

后端 未结 8 2210
星月不相逢
星月不相逢 2020-11-27 11:06

I\'m trying to make a trivial postMessage example work...

  • in IE10
  • between windows/tabs (vs. iframes)
  • across origins

8条回答
  •  隐瞒了意图╮
    2020-11-27 11:32

    == WORKING SOLUTION IN 2020 without iframe ==

    Building on answer by tangle, I had success in IE11 [and emulated IE10 mode] using following snippet:

    var submitWindow = window.open("/", "processingWindow");
    submitWindow.location.href = 'about:blank';
    submitWindow.location.href = 'remotePage to comunicate with';
    

    Then I was able to communicate using typical postMessage stack, I'm using one global static messenger in my scenario (alotough I don't suppose it's of any signifficance, I'm also attaching my messenger class)

    var messagingProvider = {
        _initialized: false,
        _currentHandler: null,
    
        _init: function () {
            var self = this;
            this._initialized = true;
            var eventMethod = window.addEventListener ? "addEventListener" : "attachEvent";
            var eventer = window[eventMethod];
            var messageEvent = eventMethod == "attachEvent" ? "onmessage" : "message";
    
            eventer(messageEvent, function (e) {
                var callback = self._currentHandler;
                if (callback != null) {
                    var key = e.message ? "message" : "data";
                    var data = e[key];
                    callback(data);
                }
            }, false);
        },
    
        post: function (target, message) {
            target.postMessage(message, '*');
        },
    
        setListener: function (callback) {
            if (!this._initialized) {
                this._init();
            }
    
            this._currentHandler = callback;
        }
    }
    

    No matter how hard I tried, I wasn't able to make things work on IE9 and IE8

    My config where it's working:
    IE version: 11.0.10240.16590, Update versions: 11.0.25 (KB3100773)

提交回复
热议问题