如何在另一个中包含html文件。我尝试了很多代码。没有

时间:2015-10-24 21:14:59

标签: html include

我的文件名为a.html,代码如下:

<!DOCTYPE html>
<html lang="en-US">
<head>
<title>Restaurant Gaststätte Gartenfreunde-Ehningen</title>
<meta charset="utf-8" />
<meta name="generator" content="iloapp 2.1"/>
<link rel="shortcut icon" href="//ilostatic.one.com/iloapp/gallery/images/favicon.ico" type="image/vnd.microsoft.icon"/>
</head>
<body>
<script>
   (function () {
     var script = document.createElement('script');
     script.src = '//ilostatic.one.com/iloapp/gallery/js/init.js?' + (new Date).getTime();
     document.documentElement.firstChild.appendChild(script);
  })();
</script>
<noscript><iframe src="//ilostatic.one.com/iloapp/gallery/html/nojs_1_en-US.html" frameBorder="0" style="position: absolute; left: 0px; top: 0px; width: 100%; height: 100%;"></iframe></noscript>
</body>
</html>

这是一个看起来像这样的画廊:link

我想在此处加入:link

需要一些帮助。

3 个答案:

答案 0 :(得分:1)

如果您使用的是Jquery,则可以执行以下操作:

<html> 
  <head> 
    <script src="jquery.js"></script> 
    <script> 
    $(function(){
      $("#includedContent").load("b.html"); 
    });
    </script> 
  </head> 

  <body> 
     <div id="includedContent"></div>
  </body> 
</html>

如果您正在寻找原始Javascript DOM,那么您可以执行以下操作:

function loadDoc() {
  var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (xhttp.readyState == 4 && xhttp.status == 200) {
      document.getElementById("demo").innerHTML = xhttp.responseText;
    }
  }
  xhttp.open("GET", "b.html", true);
  xhttp.send();
}

答案 1 :(得分:1)

  

您可以使用SSI(Sever Side Includes)包含来自其他文件的HTML代码而无需编写脚本。

只需使用.shtml扩展名命名您的文件,然后在您要包含文件的位置写下类似内容(例如index.html):

<!--#include virtual="/galerie/index.html" -->

默认情况下,SSI默认使用.shtml个文件而不进行任何配置。

Web服务器将处理.shtml文件,查找其中的SSI指令并处理它们。

答案 2 :(得分:0)

我在脚本中成功整合了galerie。 :)感谢所有人为你提示。我使用过iframe。最终工作