I have the following code
function exibirDialog(div) {
$("#divDialogo").ready(function() {
$("#divDialogo").dialog({
open: function() { },
close: function() { $(this).dialog("destroy"); },
buttons: {
"Print": function() {
var popUp = window.open('Print.aspx', "Print", "menubar=0,location=0,height=700,width=700");
//alert(popUp);
var x = popUp.document.getElementById('content');
div.clone().appendTo(x);
},
"Close": function() { $(this).dialog("destroy"); }
}
});
});
}
Its like: When I click in the Print button the system opens a popup (print.aspx)
and copy the div element into the ‘content’ element.
The weird beheavior is: This only works when I uncomment the line “//alert(popUp);”
Somebody knows how I do to do this works without the alert?
The alert gives the page just enough time to load. Your line
var x = popUp.document.getElementById('content');is executed before thecontentobject has the opportunity to be rendered. And because it is not yet on the page, you cannot yet append to it.To wait for the page to load, use the
window.openerobject. More information about that is available here: http://www.webreference.com/js/tutorial1/opener.html