Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 571
Rikard Avatar asked Feb 17 '14 22:02

Rikard


1 Answers

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);
like image 180
Midhun Murali Avatar answered Oct 26 '22 22:10

Midhun Murali