0

This code I have works in Chrome/FF/safari but not IE9. I am trying to figure out whats wrong with IE.

Domain1.com has an iframe hosted on domain2.com - the iframe triggers a popup (hosted on domain2.com) and then a link on that popup a) forwards the domain1.com page to somewhere on domain2.com and b) closes the popup.

I have this code based on this post/answer

1) domain1.com (has iframe on it and IE specific code for handling event)

  <script type="text/javascript">
    if(navigator.appName == "Microsoft Internet Explorer")          
        window.attachEvent("onmessage", receiveMessage);
    else
        window.addEventListener("message", receiveMessage, false);            

    function receiveMessage(e) {
      if(e.origin == "http://www.domain2.com") //important for security
        if(e.data.indexOf('redirect:') == 0)
          document.location = e.data.substr(9);
    }
  </script>
<iframe src="http://www.domain2.com/iframetest_deleteme.html" width="400" height="150">      
</iframe>

2) domain2.com (contents of iframe, JS is just a poup)

<script type="text/javascript" >
 jQuery(function($){ 
        $("a[rel*=external]").click(function(){ 
            window.open("http://domain2.com/iframetest_deleteme_popup.html", "", "location=0, menubar=0, resizable=no, toolbar=no, menubar=no, scrollbars=no, width=300, height=100")
            return false; 
        });
 }); 
 </script>
<a href="#" rel="external">open popup from iframe</a>

3) domain2.com (contents of popup - JS should redirect parent of popup)

<script type="text/javascript">
 jQuery(function($){ 
        $("a[rel*=external]").click(function(){             
            opener.parent.postMessage('redirect:http://www.google.com', 'http://domain1.com');
            window.close(this);         
            return false; 
        });
 }); 
 </script>

 <p><a href="#" rel="external">javascript link</a></p>

I've been playing with this for a long while and cannot figure out why IE9 isn't working with it.

It is live and can be tested / seen working in all non-IE browsers here: http://alexhays.com/test/

Community
  • 1
  • 1
alexbooots
  • 383
  • 6
  • 22

1 Answers1

1

postmessage doesn't work on ie8 & ie9 for popup comminucation

http://www.felocity.com/article/window_postmessage_problems_and_workarounds_for_ie8/

aWebDeveloper
  • 36,687
  • 39
  • 170
  • 242