7

I made a new window

var win = window.open("", "", "width=400, height=200");

and I want to reach its body with

var $windowBody = $(win.document.body);

and from there use methods like .find(), .html()

This works good on FF & Chrome but not IE. Found also a related post to this one.

How to fix this in IE? ie, how to make this work cross browser?

jsFiddle - notice that the close button never shows up in IE.

Community
  • 1
  • 1
Rikard
  • 7,485
  • 11
  • 55
  • 92
  • what kind of error do you get from IE? – Luis Masuelli Feb 17 '14 at 22:36
  • @LuisMasuelli, `Exception thrown and not caught`. Added a jsFiddle to the question. – Rikard Feb 17 '14 at 22:36
  • 2
    You need to wait on the `document.ready` state before doing anything to the popup window. JavaScript doesn't wait for completion of previous syntax. –  Feb 17 '14 at 22:38
  • @Allendar, can you explain more / post a example? Do you mean this: http://jsfiddle.net/XL7LR/11/ - using a onload event? – Rikard Feb 17 '14 at 22:40
  • 1
    It should be something in that fashion yes. I'm currently not in the vicinity of a Windows PC, so I can't test it at the moment. It seems JSFiddle doesn't play nice with these mechanics. It doesn't show correctly on my MacBook either. –  Feb 17 '14 at 22:46
  • by adding a script with window.onload in the popup that calls window.opener.onpopuploaded function defined in the main body will get this called? i cant test that i am on a mac and i have no explorer at all – markcial Feb 18 '14 at 07:38

1 Answers1

1

Please use the below code to fix it in IE

var content = $('#content');

$('#open').on('click', function () {

    var win = window.open("", "", "width=400, height=200");
    $newWindow = $(win.document.body);    
    $newWindow.html(document.getElementById("content").innerHTML);    
    $newWindow.find('#close').on('click', function () {
        win.close();
    });
});

or use:

var content = $('#content');

// and then 
$newWindow.html(content);
Rikard
  • 7,485
  • 11
  • 55
  • 92
Midhun Murali
  • 2,089
  • 6
  • 28
  • 49