[英]How do I include html file inside another html file
I know that there are a lot of answers to this question, but I have trying them all and I could not resolve this problem. 我知道这个问题有很多答案,但我已经尝试了所有这些问题,但我无法解决这个问题。 My specific problem is that I have two files,
index.html
and part1.html
, and I need include part1.html
into index.html
. 我的具体问题是我有两个文件,
index.html
和part1.html
,我需要将part1.html
包含到index.html
。
I have tried using: 我尝试过使用:
.load() function of jquery.
<!--#include file="part1.shtml" -->
include with html like <!--#include file="part1.html" -->
but this has resolved my problem, so why so I need it? 但这解决了我的问题,为什么我需要呢? I have a page with a lot of code and in this moment is almost impossible to work.
我有一个包含大量代码的页面,在这一刻几乎不可能工作。 Why don't use a server language?
为什么不使用服务器语言? I do, but I work with a framework in R called shiny and believe me server language is not a solution xD.
我这样做,但我在R中使用一个名为shiny的框架,相信我的服务器语言不是解决方案xD。
When I use .load()
I get an error XMLHttpRequest cannot load file:///home/... Origin null is not allowed by Access-Control-Allow-Origin
. 当我使用
.load()
出现错误XMLHttpRequest cannot load file:///home/... Origin null is not allowed by Access-Control-Allow-Origin
。
Thanks for all. 谢谢大家。
use jquery
<html>
<head>
<script src="jquery.js"></script>
<script>
$(function{
$("#includedContent").load("b.html");
});
</script>
</head>
<body>
<div id="includedContent"></div>
</body>
</html>
.load
should be working fine. .load
应该工作正常。 A quick example of this, say you have the following div: 一个简单的例子,说你有以下div:
<div id="contentDiv"></div>
Using jQuery, you can load your separate HTML file into that div: 使用jQuery,您可以将单独的HTML文件加载到该div中:
$(document).ready(function() {
$("#contentDiv").load("part1.html");
});
It's something to do with SOP(same origin policy) recently I had the same issue...so I used this...hope you can do it like this...here's the link : http://jsfiddle.net/JKZ2h/1/ my html code: 这与SOP(同源策略)有关,最近我遇到了同样的问题...所以我用过这个...希望你能这样做......这里是链接: http : //jsfiddle.net/JKZ2h / 1 /我的HTML代码:
<li><a href="#" class="about-link">About Us</a></li>
<div class="bdy"></div>
my js code: 我的js代码:
$('.about-link').click(function() {
$('.bdy').html('<iframe sandbox="allow-scripts allow-same-origin" style="width:100%;height:435px;" src="http://www.erail.in/?R=12622"><iframe>');
})
or even this works for a static webpage : this inside any function...works..: 甚至这适用于静态网页:这里面的任何功能...工作..:
$('.bdy').html('<object style="width:100%;height:435px;"data="http://www.jhsoftech.com/contactus.php">');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.