2015-10-20 98 views
0

有没有办法在一个HTML文件中包含一个HTTP请求(包含text/html或text/plain)的内容?当然,这可以通过AJAX或在服务器端完成,但我对纯粹的浏览器HTML方式感兴趣。也许使用<link>标记,或者我不熟悉的一些HTML5方法?如何从纯html加载html文本?

例如: 的index.html:

<!DOCTYPE html> 
<html> 
<head></head> 
<body> 
    <p>This is my text loaded from the original document</p> 
    <p>This is text I want to load from another file: <span id="other"><!-- link other resource here --></p></span> 
</body> 
</html> 

otherResource.html:

<p>This is from another resource</p> 

回答

1

你可以尝试使用iframe

<iframe src="page.html" width="300" height="300"></iframe> 
+0

我认为这是最好的非代码方式。 – nycynik

0

如果你正在考虑包括文本从另一个网页,如一个页脚或标题,只是想找到一种方法,包括,你可以尝试的模板引擎。

模板信息:http://www.creativebloq.com/web-design/templating-engines-9134396

例如从上面的链接EmbedJS:

new EJS({ url: "template.ejs" }).render({ name: "Jack" }); 

将允许你包括一个名为template.ejs的模板。

另一种选择是使用工具,如Dreamweaver来完成它。

最后,你可以在将html放到服务器上之前用脚本来完成。