title: window.onload not called using ajax loadXMLDoc
body: <p>I use JavaScript and AJAX's XMLHttpRequest to load content from different *.html in order to advance from my initial top page index.html through other html page.</p>
  
  <p>To add some dynamic behaviour (not yet added) I desire to automatically call a JavaScript function setSelected() via <code>window.onload=setSelected();</code> (please see below how I do it precisely).</p>
  
  <p>This works very well when I load from my top page index.html the content of my first html page introduction.html. To check if setSelected() is called I put an alert message and a log-print to the console.</p>
  
  <p>In index.html:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"/&gt;
  &lt;link href="css/base.css" rel="stylesheet" type="text/css"/&gt;
  &lt;script src="./js/my_js_lib.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;div id="bigbackground" class="clearfix"&gt;
      &lt;div id="smallbackground" class="clearfix"&gt;
          &lt;iframe src="source/introduction.html"&gt;&lt;/iframe&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>In introduction.html:</p>
  
  <pre><code>&lt;head&gt;
  &lt;link href="../css/base.css" rel="stylesheet" type="text/css" /&gt;
  &lt;script src="../js/my_js_lib.js"&gt;&lt;/script&gt;
  &lt;script&gt;
      window.onload=setSelected();
  &lt;/script&gt;
  &lt;/head&gt;
  
  &lt;article id='id_intro' onload="setSelected()"&gt;
  &lt;div class='clearfix'&gt;
      &lt;button value="Next" onclick="loadXMLDoc('instructions.html',
      'id_intro')" class="button_blue"&gt;Next&lt;/button&gt;
  &lt;/div&gt;
  &lt;/article&gt;
  </code></pre>
  
  <p>In my_js_lib.js:</p>
  
  <pre><code>function loadXMLDoc(url, id)
  {
      var xmlhttp;
      if (window.XMLHttpRequest)
      {   // code for IE7+, Firefox, Chrome, Opera, Safari
          xmlhttp=new XMLHttpRequest();
      }
      else
      {   // code for IE6, IE5
          xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
      xmlhttp.onreadystatechange=function()
      {
          if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200)
          {                  
          document.getElementById(id).innerHTML=xmlhttp.responseText;
          }
      }
      xmlhttp.open("GET",url,true);
      xmlhttp.send();
  }
  
  function setSelected()
  {
      alert('I am setSelected');
      console.log('I am setSelected');
  }
  </code></pre>
  
  <p>However, utilizing the same syntax at the 2nd loaded html content page instructions.html does not invoke again setSelected() via window.onload.
  I do not receive the alert message nor the log print at the console.</p>
  
  <p>In instructions.html:</p>
  
  <pre><code>&lt;head&gt;
  &lt;script src="../js/my_js_lib.js"&gt;&lt;/script&gt;
  &lt;script&gt;
      window.onload=setSelected();
  &lt;/script&gt;
  &lt;/head&gt;
  
  &lt;article id='id_instru' onload="setSelected()"&gt;
  &lt;div class='clearfix'&gt;
  
  &lt;button value="Intro" onclick="loadXMLDoc('introduction.html', 'id_instru')" class="button_blue"&gt;Introduction&lt;/button&gt;
  &lt;button value="Next"  onclick="loadXMLDoc('speakers_inauguration.html', 'id_instru')" class="button_blue"&gt;Next&lt;/button&gt;
  &lt;/div&gt;
  &lt;/article&gt;
  </code></pre>
  
  <p>Moreover, when going back to introduction.html (by clicking on the first button with value="Intro"), again neither the alert message nor the log print at the console appear.</p>
  
  <p>I imagine 2 possible sources of error: </p>
  
  <p>a) The <code>window.onload=setSelected();</code> is only set once at the html header when the initial top page index.html gets loaded, but it may not be added to the html  section when I load further content via AJAX, right?</p>
  
  <p>b) The onload event handler of the HTML5 element  doesn't get triggered when I load it the way I do via AJAX.</p>
  
  <p>Best,</p>