2015-10-20 68 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放到服務器上之前用腳本來完成。