Take the 2-minute tour ×

I've been working on a popup window that interacts with the window.opener. I found a specific problem with IE not working when trying to append an object. I've set up a demo page here.

Basically what the demo does is opens a popup window with a button. It is intended to highlight portions of the page as I described in my previous question.

In the demo, clicking on the popup window button appends two divs to the window.opener. One div is added as a string and the second is added as an object. I get an error in IE when trying to append an object. Here is the javascript:

 $('#clicked').empty().show().html('Click detected!').fadeOut();
 var str = '<div class="highlight" style="position:absolute;height:50px;width:50px;left:150px;top:100px;background:#fc0;zIndex:99;">str</div>';
 var obj = $('<div/>', {
  'class': 'highlight',
  css: {
   position:   'absolute',
   height:     '50px',
   width:      '50px',
   left:       '100px',
   top:        '100px',
   background: '#08f',
   zIndex:     99
 try { $(window.opener.document.body).append(obj); } catch(err) { alert(err.description) };

So, I'm asking for help in tracking down the problem with jQuery.

share|improve this question
have you taken a look at jQuery UI? they have a dialog component which may help: jqueryui.com/demos/dialog –  Luke Duddridge Feb 18 '10 at 16:01
Hi Luke and thanks for the comment, but I want to add a div to the window opener to highlight a section of the page. It needs to be positioned and semi-transparent, so a dialog box is not what I want. –  Mottie Feb 18 '10 at 16:20
add comment

1 Answer

up vote 3 down vote accepted

I don't think that IE will let you append an element created in one window into the DOM of another window. It's really picky about that. Similarly, it gets freaked out sometimes if you pass constructed Javascript objects from one window to another, especially if the creating window later goes away.

Try using window.opener.$("<div/>") to create your element.

share|improve this answer
That is a very nice and elegant solution. So I guess I should ask if I need to continue pursuing the problem with jQuery? –  Mottie Feb 18 '10 at 16:13
It's not really a problem with jQuery - there's really nothing sane that the library can do for you, since when you create an element it has no idea that you're going to try and stick it in the DOM of another window. –  Pointy Feb 18 '10 at 16:17
ok then, thanks for your help :) –  Mottie Feb 18 '10 at 16:21
add comment

Your Answer


