如何在 <div> 中加载 HTML 页面使用 JavaScript? [英] How do I load an HTML page in a &lt;div&gt; using JavaScript?

查看:31
本文介绍了如何在 <div> 中加载 HTML 页面使用 JavaScript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在

中加载 home.html.

<a href="#" onclick="load_home()">首页</a>

<div id ="内容">

<脚本>函数 load_home(){document.getElementById("content").innerHTML='<object type="type/html" data="home.html" ></object>';}

这在我使用 Firefox 时工作正常.当我使用谷歌浏览器时,它要求插件.如何让它在 Google Chrome 中运行?

解决方案

我终于找到了问题的答案.解决办法是

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

I want home.html to load in <div id="content">.

<div id="topBar"> <a href ="#" onclick="load_home()"> HOME </a> </div>
<div id ="content"> </div>
<script>
      function load_home(){
            document.getElementById("content").innerHTML='<object type="type/html" data="home.html" ></object>';
  }
</script>

This works fine when I use Firefox. When I use Google Chrome, it asks for plug-in. How do I get it working in Google Chrome?

解决方案

I finally found the answer to my problem. The solution is

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

这篇关于如何在 <div> 中加载 HTML 页面使用 JavaScript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆