Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
82
rated 0 times [  84] [ 2]  / answers: 1 / hits: 37986  / 15 Years ago, tue, august 11, 2009, 12:00:00

I open a new window using the following code:



purchaseWin = window.open(Purchase.aspx,purchaseWin2, location=0,status=0,scrollbars=0,width=700,height=400);


I want to access the dom tree of the purchaseWin, e.g.



purchaseWin.document.getElementById(tdProduct).innerHTML = 2;


It doesn't work. I can only do this:



purchaseWin.document.write(abc);


I also try this and it doesn't work too:



 $(purchaseWin.document).ready(function(){

purchaseWin.$(#tdProduct).html(2);

});


What should I do?


More From » javascript

 Answers
21

With jQuery, you have to access the contents of the document of your child window:



$(purchaseWin.document).ready(function () {
$(purchaseWin.document).contents().find('#tdProduct').html('2');
});


Without libraries, with plain JavaScript, you can do it this way:



purchaseWin.onload = function () {
purchaseWin.document.getElementById('tdProduct').innerHTML = '2';
};


I think that the problem was that you were trying to retrieve the DOM element before the child window actually loaded.


[#98942] Friday, August 7, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
austynp

Total Points: 505
Total Questions: 118
Total Answers: 106

Location: Tajikistan
Member since Sun, Aug 29, 2021
3 Years ago
austynp questions
;