4

I am trying to move a DOM node from the "root" page to a new pop-up that is created via window.open(). Here is the code I am using.

var win = window.open('/Search/Print', 'printSearchResults'),
    table = $('#printTable');
win.document.close();
setTimeout(function () {
    var el = win.document.createElement("table");
    el.innerHTML = table.html();
    win.document.body.appendChild(el);
}, 40);

It works in Chrome, but in IE8, I receive the following error: "Unknown runtime error."

I've also tried it this way:

var p = window.open('/Search/Print', 'printSearchResults'),
    table = $('#printTable');
setTimeout(function () {
    p.document.body.appendChild(table.clone(false)[0]);
}, 100);

Doing it this way, I receive "No such interface supported" in IE8. Again, Chrome works fine.

Does anyone have a way to do what I'm trying to achieve?

Here is the HTML for the pop-up window just for the sake of completeness:

<!DOCTYPE html>
  <html>
  <head>
      <title>Print Results</title>
  </head>
  <body>
  </body>
</html>
arb
  • 7,753
  • 7
  • 31
  • 66
  • I don't know if this is the issue, but arbitrary `setTimeout()` calls are a really bad way of dealing with an async load. Try using an `onload` handler for your new window instead. – nrabinowitz Aug 08 '12 at 16:30

2 Answers2

1

To be able to use iframes and new windows, you should initialise them with addres: about:blank, before you write() to them. Also note that loading/opening the window/frame takes time, so you cannot write to them at right away. set a timeout, or check onload. Please see this answer for more info.

Good luck!

Community
  • 1
  • 1
GitaarLAB
  • 14,536
  • 11
  • 60
  • 80
1

I tested your code on IE9 ( and IE8/7 browser mode).

Instead of el.innerHTML = table.html();

using jquery $(el).html(table.html()); fixed the issue.

Vijay Sirigiri
  • 4,653
  • 29
  • 31