ホームページ用に設計されたjsファイルに取り組んでいます。ナビゲーション メニュー バーを使用して、このページから他のページに移動したいと考えています。ターゲット ページは同じテンプレート (html コード) を共有しているため、特定のページに移動するには、xml ファイルに保存されている特定のコンテンツを読み込み、そのコンテンツをターゲット ページに渡す必要があります。
function loadFileToElement(filename, elementId)
{
var xhr = new XMLHttpRequest();
try
{
xhr.open("GET", filename, false);
xhr.send(null);
}
catch (e) {
window.alert("Unable to load the requested file.");
}
// Until this point I can load the specific content
// How can I get from the url of the target page
// a js document object, so that I can call getElementById(Id)
// to pass the specific content.
// For instance: Im currently opnening X1:= www.main.com
// und I would like to switch to X2 := www.targetpage.com
// target page which contains html the templat.
// The problem **document** represents currently X1
// but i would like to set it to X2 so that I can pass
// the content of xhr.responseText to it
var component = **document**.getElementById(elementId);
component.innerHTML = xhr.responseText;
}
Thanks