title: Javascript - Get 'external' HTML document body
body: <p>I have a website which resides in a directory.  On a particular user operation that website's javascript needs to get the body from an 'external' HTML document which resides in an immediate subdirectory of the primary webpage.  </p>
  
  <p>Example:<br>
  Primary webpage directory<br>
  |___  TutorialFiles (the 'external' HTML document subdirectory)  </p>
  
  <p>When the user clicks on a link it executes its OnClick() javascript function.<br>
  The following is what I am trying to use, but it is not working.  </p>
  
  <pre><code>function DisplayDocument(thisDoc) {
      //alert("Display " + thisDoc + " Doc Here!");
  
      var loc = window.location.pathname;
      var dir = loc.substring(0, loc.lastIndexOf('/'));
  
      var HTMLDoc = "./TutorialFiles" + "/" + thisDoc;
  
      var HTMLDocContent = getBody(HTMLDoc);
      document.getElementById("page_content_wrapper").innerHTML = getBody(HTMLDocContent);
      return false;
  }
  
  function getBody(content) { 
     var x = content.indexOf("&lt;body");
     x = content.indexOf("&gt;", x);    
     var y = content.lastIndexOf("&lt;/body&gt;"); 
     return content.slice(x + 1, y);
  } 
  </code></pre>
  
  <p>That above javascript code does not 'see' the external document in the subdirectory  TutorialFiles and therefore cannot get its 'body'.  </p>
  
  <p>What am I doing wrong?</p>
  
  <p>Thanks</p>