Is cross-origin postMessage broken in IE10?

后端 未结 8 2192
星月不相逢
星月不相逢 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:26

    Create a proxy page on the same host as launcher. Proxy page has an iframe with source set to remote page. Cross-origin postMessage will now work in IE10 like so:

    • Remote page uses window.parent.postMessage to pass data to proxy page. As this uses iframes, it's supported by IE10
    • Proxy page uses window.opener.postMessage to pass data back to launcher page. As this is on same domain - there are no cross-origin issues. It can also directly call global methods on the launcher page if you don't want to use postMessage - eg. window.opener.someMethod(data)

    Sample (all URLs are fictitous)

    Launcher page at http://example.com/launcher.htm

    
    
        
            Test launcher page
            
        
        
    
        
        
         

    Proxy page at http://example.com/proxy.htm

    
    
        
            Proxy page
            
        
        
    
        
    
        
    
        
    
    

    Remote page at http://example.net/remote.htm

    
    
        
            Remote page
            
        
        
    
        
        
        

    Remote page

提交回复
热议问题