简体   繁体   English

在div中加载外部html页面对我不起作用

[英]load external html page in div doesn't work for me

i have a web interface that includes a menu and a div with id "content" and i want to load many external html pages in the div using the menu, i have a problem in the code it shows only blanc. 我有一个包含菜单和ID为“ content”的div的Web界面,我想使用该菜单在div中加载许多外部html页面,我在代码中仅显示blanc有问题。 this is the script : 这是脚本:

 <script> 
function check() {
 document.getElementById("content").innerHTML='<object type="text/html" 
data="form.html" ></object>';
}
</script>

and this is the code of the menu (just a part of the code): 这是菜单的代码(只是代码的一部分):

 <li><a href="#home" onclick="check();">Acceuil</a></li>
  <li>
   <a href="gp">Gestion du personnel</a>

  </li>

and here where i want to load the div: 在这里我要加载div:

<div id="content"> 

<div class="background"></div>
 <div class="Bienvenue"><b>  &emsp; Bienvenue sur la page  d'accueil</b> 
</div>

 </div>

i don't know if it's necessary that the div must be empty, so please if you know anything help me 我不知道div是否必须为空是否必要,所以请您是否有任何帮助

i changed 我变了
<object type="text/html" data="form.html" ></object>'; with <embed type="text/html" src="form.html" ></embed>'; <embed type="text/html" src="form.html" ></embed>'; it works now 现在有效

I'm not really sure using an object tag for loading HTML is standard, doing this appears to work similar to an IFrame , so I would personally use that. 我不太确定使用object标签加载HTML是否是标准的,这样做似乎类似于IFrame ,所以我个人会使用它。 Or better still load content with either ajax or fetch .. 或者最好还是用ajaxfetch ..加载内容。

Saying all this using the object tag does seem to work, here is a working snippet. 使用object标签说所有这些似乎确实可行,这是一个有效的代码段。 I've also include the IFrame version commented out. 我还包括已注释掉的IFrame版本。

 function check() { document.getElementById("content").innerHTML='<object type="text/html" data="https://stacksnippets.net/"></object>'; //document.getElementById("content"). // innerHTML='<iframe src="https://stacksnippets.net/"/>'; } 
 <li><a href="#home" onclick="check();">Acceuil</a></li> <li> <a href="gp">Gestion du personnel</a> </li> <div id="content"> <div class="background"></div> <div class="Bienvenue"><b> &emsp; Bienvenue sur la page d'accueil</b> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM