Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I detect window opener in IE

Tags:

javascript

I couldn't find any good answers on stack - they related to dialog boxes, text editors, and one guy used VBScript.

I need to post a message to the window opener. This works fine in FF, Chrome and Opera, but window.opener is null in IE8-10.

I am using window.open to make the new window appear.

I even tried this:

var new_window = window.open( url, '_social', "height=600,width=600" );

if ( !new_window.opener ) {
  new_window.opener = window;
}

The opened window simply has a script tag like this:

<script type="text/javascript">
var data = {
  type : 'redirect',
  destination : '<?= $destination; ?>'
};
window.opener.postMessage( JSON.stringify( data ), '*' );
window.close();
</script>

I opened the console and logged window.opener which comes up null, so I don't think it has anything to do with the DOM being ready or not.

The window does redirect a few times before landing on the page with the script tag.

like image 1000
Dave Stein Avatar asked Nov 12 '22 22:11

Dave Stein


1 Answers

Actually, the problem may not have anything to do with window.opener – because IE8+ can only use postMessage to communciate with an iframe.

http://blogs.msdn.com/b/ieinternals/archive/2009/09/16/bugs-in-ie8-support-for-html5-postmessage-sessionstorage-and-localstorage.aspx

like image 124
Ben Vinegar Avatar answered Nov 15 '22 12:11

Ben Vinegar