0

I am trying to access a popup via JavaScript and write some content to a certain div.

This should be relatively easy, however for some reason it does not work.

At some point in my script I execute the following code:

var x = window.open('report_handle/test.html', "Popup", "width=300,height=300");

x.document.getElementById('test_id').innerHTML = '<br>Some new content!';

The HTML is as follows:

<!DOCTYPE html>

<html>
    <body>
        <div id="test_id"></div>
    </body>
</html>

I get the following error by using firebug:

TypeError: x.document.getElementById(...) is null


x.document.getElementById('test_id').innerHTML = '<br>Some new content!';
Andreas
  • 545
  • 2
  • 11
  • 24
  • if you remove the x and just have `document.getElementById('test_id').innerHTML = '
    Some new content!';` does it work? i don't think you can assign a variable to the `window.open` method
    – Paul Fitzgerald Aug 18 '16 at 16:48
  • 1
    `window.open()` is asynchronous, so your second statement is executing before the document is loaded into the window. – Barmar Aug 18 '16 at 17:09
  • See http://stackoverflow.com/questions/3030859/detecting-the-onload-event-of-a-window-opened-with-window-open/3030893#3030893 – Barmar Aug 18 '16 at 17:09

0 Answers0