1

My preliminary code to do this is something like this.

$j(document).ready(function() {
   var w = window.open(childPage);

   $j(w.document).ready(function() {
      $j('#DestinationElement', w.document).html($j('#SourceElement').html());
   });
});

However, this only works for me when I set a breakpoint on the html injection statement, meaning that it's not really waiting for the child window to be ready before doing the injection.

Can somebody fix this? Thanks.

user420667
  • 6,552
  • 15
  • 51
  • 83

1 Answers1

0

Here are some alternatives: attach an event listener to the window onload event. Waiting for child window loading to complete (but in IE you would use attachEvent to 'onload')

In the child window itself, get the opener's html when the document is ready.

$j(document).ready(function() {
   $j('#DestinationElement').html($j('#SourceElement', window.opener.document).html());
});

But it still bothers me that I don't see why the original solution fails.

Community
  • 1
  • 1
user420667
  • 6,552
  • 15
  • 51
  • 83
  • 1
    Not sure why the original fails. Probably the jquery uses the Array, String, etc. types of the parent window, so type check fails. Another option that the `w.document` is not yet created when you give it to jquery. Some of the browsers create the new document a few hundred msecs later, so it is not something sync. Capturing page load of the child window is far from trivial... Here is how you can do it in most of the browsers: https://stackoverflow.com/a/51908787/607033 – inf3rno Aug 28 '18 at 14:59