title: How do I change the background image of 1 HTML window from another HTML window?
body: <p>As the title of this question sez :</p>
  
  <p>How do I change the background image of 1 HTML window from another HTML window ?</p>
  
  <p>I have 9 HTML windows.</p>
  
  <p>Call them ‘HTMLWindow_0’ &amp; HTMLWindow_1’ through ‘HTMLWindow_8’.</p>
  
  <p>HTML Window1 has a background image and a set of 8 buttons.</p>
  
  <p>Each button opens up a new HTML window with a different background image. </p>
  
  <p>Call them ‘HMTLWindow_1’ though  ‘HTMLWindow_8’.</p>
  
  <p>In other words, Button–n on ‘HTMLWindow_0’ creates ‘HTMLWindow_n’.</p>
  
  <p>Each of the HTML windows created by the set of buttons on ‘HTMLWindow_0’ has a background image associated with it.</p>
  
  <p>Background image x is associated with HTMLWindow_x.</p>
  
  <p>The HTML &amp; Javascript for ‘HTMLWindow_0’ is in a file called ‘HTMLWindow_0.html’.</p>
  
  <p>The HTML for ‘HTMLWindow_1’ through ‘HTMLWindow_8’ is in a file called ‘HTMLWindow_x.html’.</p>
  
  <p>The set of file pathnames for the images used as backgrounds for the HTML windows 1 though 8 are stored in a Javascript array called ‘Image_Array’ in the file ‘HTMLWindow_0.html’.</p>
  
  <p>The HTML that acts upon button clicks in HTMLWindow_0 is as follows :</p>
  
  <pre><code>&lt;div class="toc_button_01"&gt;&lt;button onClick="changePage ('Toc 01',  2)"&gt; &lt;/button&gt;&lt;/div&gt;
   &lt;div class="toc_button_02"&gt;&lt;button onClick="changePage ('Toc 02',  4)"&gt; &lt;/button&gt;&lt;/div&gt;
  &lt;div class="toc_button_03"&gt;&lt;button onClick="changePage ('Toc 03',  5)"&gt; &lt;/button&gt;&lt;/div&gt;
  &lt;div class="toc_button_04"&gt;&lt;button onClick="changePage ('Toc 04',  6)"&gt; &lt;/button&gt;&lt;/div&gt;
  &lt;div class="toc_button_05"&gt;&lt;button onClick="changePage ('Toc 05',  7)"&gt; &lt;/button&gt;&lt;/div&gt;
  &lt;div class="toc_button_06"&gt;&lt;button onClick="changePage ('Toc 06',  8)"&gt; &lt;/button&gt;&lt;/div&gt;
  &lt;div class="toc_button_07"&gt;&lt;button onClick="changePage ('Toc 07',  9)"&gt; &lt;/button&gt;&lt;/div&gt;
   &lt;div class="toc_button_08"&gt;&lt;button onClick="changePage ('Toc 08', 10)"&gt; &lt;/button&gt;&lt;/div&gt;
  </code></pre>
  
  <p>In other words,  clicking on any of the 8 buttons activates a JavaScript function called ‘changepage’.</p>
  
  <p>‘changepage’ looks like this :</p>
  
  <pre><code>function changePage (buttonName,
              buttonNumber)
  {
      alert (   "We're in the 'changePage' function !" 
              + "\n"
              + "We just clicked on the "
              +  buttonName
              + " button !"
              + "\n"
              + "Button Number  = "
              +  buttonNumber
              + "\n"
              + "Current Page URL = "
              +  Image_Array [buttonNumber]); 
  
  document.getElementById("image1").src = Image_Array [buttonNumber];
      generatePageContent (buttonNumber);
  
  } // End of function changePage ()
  </code></pre>
  
  <p>‘changepage’ in turns calls another JavaScript function called ‘    generatePageContent’.</p>
  
  <p>‘generatePageContent’ is the actual JavaScript function that creates the new HTML windows 1 through 8 depending on which button was pushed on ‘HTMLWindow_0’.</p>
  
  <p>‘generatePageContent’ looks like this :</p>
  
  <pre><code>function generatePageContent (buttonNumber)
  {
      alert (   "We're in the 'generatePageContent' function !"
              + "\n"
              + "Button Number  = "
              +  buttonNumber
              + "\n"
              + "Current Page URL = "
              +  Image_Array [buttonNumber]); 
  
      var newWindow = window.open (' HTMLWindow_x.html ',
  '',
  'width = 788, height = 632, left = 100, top = 200, toolbar = yes');
  
      newWindow.document.getElementById("image2").src = Image_Array [buttonNumber];
  
  } // End of function generatePageContent ()
  </code></pre>
  
  <p>I have no problem creating any of the new HTML windows 1 through 8.</p>
  
  <p>In other words, the line :</p>
  
  <pre><code>var newWindow = window.open (' HTMLWindow_x.html ',
  '',
  'width = 788, height = 632, left = 100, top = 200, toolbar = yes');
  </code></pre>
  
  <p>in the Javascript function ‘generatePageContent’ will create any of the HTML windows 1 through 8 depending on which button 1 through 8 was clicked on ‘HTMLWindow_0’.</p>
  
  <p>However the line :</p>
  
  <pre><code>newWindow.document.getElementById("image2").src = Image_Array [buttonNumber];
  </code></pre>
  
  <p>in the Javascript function ‘generatePageContent’ doesn’t work. </p>
  
  <p>This is the line that is supposed to change the background image in the creatED HTML windows 1 through 8.</p>
  
  <p>It is simply ignored.</p>
  
  <p>The interesting thing is that I have no problem changing the background image in the calling HTML window ‘HTMLWindow_0’.</p>
  
  <p>The line :</p>
  
  <pre><code>document.getElementById("image1").src = Image_Array [buttonNumber];
  </code></pre>
  
  <p>inside the Javascript function ‘changepage’ handles this fine.</p>
  
  <p>So, I guess the actual question is :</p>
  
  <p>Why does :</p>
  
  <pre><code>document.getElementById("image1").src = Image_Array [buttonNumber];
  </code></pre>
  
  <p>inside the Javascript function ‘changepage’ change the background image in  ‘HTMLWindow_0’ but </p>
  
  <pre><code>newWindow.document.getElementById("image2").src = Image_Array [buttonNumber];
  </code></pre>
  
  <p>inside the Javascript function ‘generatePageContent’ doesn’t change the background image in any of ‘HTMLWindow_0’ through HTMLWindow_8’ ? </p>
  
  <p>The ‘image1’ reference inside the JavaScript function ‘changePage’ refers to the following HTML code inside file HTMLWindow_0 :</p>
  
  <pre><code>     &lt;div class="img1"&gt;
           &lt;img   id      = "image1"
                  src     = "../BookListPages/ClearingThePath/CTP-02.tiff" 
                  alt     = "Clearing The Path ..." 
                  width   = "765" 
                  height  = "580" 
                  border  = "2" 
           /&gt; &lt;!-- End of img tag. --&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>The ‘image2’ reference inside the JavaScript function ‘generatePageContent’ refers to the following HTML code inside file HTMLWindow_x :</p>
  
  <pre><code>     &lt;div class="img"&gt;
           &lt;img   id      = "image2"
                  src     = "../BookListPages/NoSuchPageForThisBook.tif" 
                  alt     = "Clearing The Path ..." 
                  width   = "765" 
                  height  = "580" 
                  border  = "2" 
           /&gt; &lt;!-- End of img tag. --&gt;
  </code></pre>
  
  <p>In other words, and simply put, I’m trying to create an HTML window from inside another HTML window using a button inside the creatING window and I want to vary the background image of the creatED HTML  window depending on which button was clicked on in the creatING window.</p>
  
  <p>What am I missing/screwing up here ?</p>
  
  <p>I apologize for the complexity of this post but I wanted to make sure that I’ve clearly explained exactly what I’m trying to do and I’ve provided all the HTML and the Javascript source involved in supporting what it is I’m trying to do here.</p>
  
  <p>Finally, I’d like to thank everyone in advance for whatever advice, help, references and suggestions you can give me towards resolving this problem.</p>