views:

17

answers:

2

im trying to dynamically create elements in the child window based on the values i have in the the parent window but no success.The child window is opening but not with the elements.Here is the code i've written,could some one please have a loot at it ? is this possible at all using javascript/jquery>

function fnOpenPrint(){

openPrint = window.open('print.htm');
childWin = openPrint.document;

var newDiv = childWin.createElement("<div id='para'>")
newDiv.innerHTML = document.forms[0].txtBranch.value;

}
A: 

try

function fnOpenPrint(){
    var openPrint = window.open('print.htm');
    openPrint.onload = function() {
        var doc = openPrint.document;

        var newDiv = doc.createElement("div");
        newDiv.id = 'para';
        newDiv.innerHTML = document.forms[0].txtBranch.value;
        doc.body.appendChild(newDiv);
    };
}

DOM manipulations in the child window must be done after it finishes loading.

Arrix
@Arrix thanks for ur answer but it didnt work :(
manraj82
@Arrix sorry m8 it did actually work,i just found out it works in safari but not in IE6...is there any why it doesnt wrk in IE?
manraj82
A: 

createElement doesn't automatically add it to the document... you'd prbably have to do this too:

childWin.body.appendChild(newDiv);
janechii