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.
Example:
Primary webpage directory
|___ TutorialFiles (the 'external' HTML document subdirectory)
When the user clicks on a link it executes its OnClick() javascript function.
The following is what I am trying to use, but it is not working.
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("<body");
x = content.indexOf(">", x);
var y = content.lastIndexOf("</body>");
return content.slice(x + 1, y);
}
That above javascript code does not 'see' the external document in the subdirectory TutorialFiles and therefore cannot get its 'body'.
What am I doing wrong?
Thanks
<body
, receives the path to the document, not magically its contents. You're also calling the function twice.) – Chris G