I posted a message yesterday asking help on cloning a window. The intent is to create a "printable" view of a web page. I was trying to do something like this:
newWin = window.open ();
var elems = document.forms[0].elements;
for (var idx = 0; idx < elems.length; idx++) {
// Filter unneeded stuff here...
// Clone the rest
var newElem = elems[idx].cloneNode (true);
newWin.document.appendChild (newElem);
}
"Jona" offered a solution:
var elems = document.body.innerHTML;
newWin.document.write (elems);
newWin.document.close ();
// Remove unneeded stuff here using removeChild
In the first case, nodes seem to be cloned, but they are not appended to the new window. In the second case I'm unable to remove elements from the new window. Being a javascript novice, can somebody tell me where I'm going wrong here?
Reopen window for 'write'?
Need to flush cache?
Redraw window?
Or is it just not possible to do this.
Scott!
newWin = window.open ();
var elems = document.forms[0].elements;
for (var idx = 0; idx < elems.length; idx++) {
// Filter unneeded stuff here...
// Clone the rest
var newElem = elems[idx].cloneNode (true);
newWin.document.appendChild (newElem);
}
"Jona" offered a solution:
var elems = document.body.innerHTML;
newWin.document.write (elems);
newWin.document.close ();
// Remove unneeded stuff here using removeChild
In the first case, nodes seem to be cloned, but they are not appended to the new window. In the second case I'm unable to remove elements from the new window. Being a javascript novice, can somebody tell me where I'm going wrong here?
Reopen window for 'write'?
Need to flush cache?
Redraw window?
Or is it just not possible to do this.
Scott!