在我的主页的某个空间添加页面

Adding page in a certain space of my homepage

本文关键字:空间 添加 我的 主页      更新时间:2023-09-26

这是我关于stackoverflow的第一个问题。

我想在我的主页的某个空间加载不同的页面。我用JavaScript尝试了很多次,但都碰壁了。我可以用框架来做。但我在想有没有别的办法。我想在用户点击链接时加载页面。

我是这样做的:

document.getElementById('aboutUs').onclick = function() {
        document.getElementById('newDiv').style.display = "none";
        document.getElementById('iFrame').style.display = "block";
    }



谢谢你! !

您需要请求加载静态内容。

希望这段代码对你有帮助

//A generic function to load the static page
function loadContent(target, staticPageLoc) {
  var r = new XMLHttpRequest(); // making request to load the static page
  r.open("GET", staticPageLoc, true);
  r.onreadystatechange = function () {
    if (r.readyState != 4 || r.status != 200) return;
    target.innerHTML = ""; // removing any previous content
    target.innerHTML = r.responseText; // response will be the static page
  };
  r.send();
}
document.getElementById('aboutUs').onclick = function() {
   loadContent(document.getElementById('id of dom element where page will load'), 'page path')
}

或者您可以探索jquery.load函数&最好在服务器上运行,否则你可能会遇到CORS