0

I create a new window using JavaScript and create element in that window, when I try use that element by using id, I can't do that and take null value

var unit_Window = window.open("", '',"height=400,width=400,status=yes");   

unit_Window.document.write("<label id='title_ID'>title</label></center>");

now when I tried to get title value using id the value return is null

unit_Window.document.getElementById('title_ID');
Mr_Green
  • 40,727
  • 45
  • 159
  • 271
Ra'fat Haj Ali
  • 111
  • 1
  • 1
  • 11

2 Answers2

0

In order to get html of an element

unit_Window.document.getElementById('title_ID').innerHTML;

Only using unit_Window.document.getElementById('title_ID'); will return the HTML element node itself not just the value.

For getting the HTML value of an element use innerHTML property of an element.

Murtaza Khursheed Hussain
  • 15,176
  • 7
  • 58
  • 83
0

I think the answer to your problem lies in timing. You need to be sure that the new window has finished loading before trying to modify its content.
See this post.

Danny

Community
  • 1
  • 1
allnodcoms
  • 1,244
  • 10
  • 14
  • I think that , but how i can know the popup window i create it finish loaded @allnodcoms – Ra'fat Haj Ali Feb 09 '15 at 10:32
  • @RafatHajAli - Check the link I posted in my answer, or the link above. You just need to put your DOM modification code in a callback that gets called when the new window's loaded. – allnodcoms Feb 10 '15 at 09:15