Rikard
Rikard

Reputation: 7805

reach content of new window.open

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.

Upvotes: 7

Views: 454

Answers (1)

Midhun Murali
Midhun Murali

Reputation: 2151

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);

Upvotes: 1

Related Questions