2011-07-31 49 views
1

我想找到一種方法,包括常見的HTML語句到我的HTML頁面。 在下面的示例中,我的網頁中的所有頁面的 都具有相同的「頁腳部分」和「公告」。 我知道它看起來並不多,但我想將所有 語句保留在「頁腳部分」和「公告」中的單獨文件中,並找到將它們包括在所有頁面中的某種方式。 我知道我可以使用JavaScript直接寫入頁面,但是我希望在 的所有頁面中都沒有啓用腳本的瀏覽器。 我認爲'鏈接'可能會做到這一點,但它不能在身體中使用。 我知道這個例子可能看起來並不多,但我想知道在開始製作更復雜的網站之前是否以及如何做到這一點 。包括爲共同的HTML

感謝 雷尼

原文: 的mypage.html

<body class = "Screen"> 
    <div class = "Page"> 
     <div class = "Header Section"> 
     </div> 
     <div class = "Content Section"> 
     </div>  
     <div class = "Footer Section"> 
      <div class = "EMail"> 
       <a href = "mailto:Support [[email protected]] 
          ?subject=Inquiry"> 
        [email protected] 
       </a>   
      </div>   
      <div class = "Organization"> 
       <ul> 
        <li>Company</li> 
        <li>City, ST</li> 
        <li>(123)456-7890</li> 
       </ul> 
      </div>   
      <div class = "Copyright"> 
       Copyright &copy; 
       2007 Company.<br> 
       All rights reserved.   
     </div> 
    </div> 
    <noscript> 
     <div class = "Bulletin" 
      id = "Notice"> 
      <b>Notice:</b> This Web-Page uses Active scripting! 
      Active scripting is not enabled in your web browser. 
     </div> 
    </noscript> 
</body> 

我想共同聲明移到單獨的文件。

文件:MyFooter.html

<div class = "Footer Section"> 
    <div class = "EMail"> 
     <a href = "mailto:Support [[email protected]] 
        ?subject=Inquiry"> 
      [email protected]Company.com 
     </a>   
    </div>   
    <div class = "Organization"> 
     <ul> 
      <li>Company</li> 
      <li>City, ST</li> 
      <li>(123)456-7890</li> 
     </ul> 
    </div>   
    <div class = "Copyright"> 
     Copyright &copy; 
     2007 Company.<br> 
     All rights reserved.   
</div> 

文件:MyBulletin.html

<noscript> 
    <div class = "Bulletin" 
     id = "Notice"> 
     <b>Notice:</b> This Web-Page uses Active scripting! 
     Active scripting is not enabled in your web browser. 
    </div> 
</noscript> 

然後在我的mypage.html文件有一些辦法,包括其他人。

<body class = "Screen"> 
    <div class = "Page"> 
     <div class = "Header Section"> 
     </div> 
     <div class = "Content Section"> 
     </div> 
     <<Some way to Include: MyFooter.html>>  
    </div> 
    <<Some way to Include: MyBulletin.html>>  
</body> 

回答

0

可以使用

  • JavaScript和AJAX請求和DOM插入
  • 服務器端包含(SSI)
  • 任何其他服務器端處理,如與一個Python,PHP或C#應用程序
0

您應該使用服務器端模板語言,如ASP.Net。

然後,您可以在服務器上包含其他源文件,或者使用更復雜的技術,例如母版頁。

0

HTML不允許這樣做。您需要一個動態網站。那裏有很多框架/解決方案。拿你的選擇。

1

您可以使用爲您簡單的例子:

<div class = "Content Section"> 
</div> 
<iframe src="MyFooter.html"></iframe> 

使用CSS,你可以風格的框架,因此不會有任何國界,固定大小等。

0

如果你只是想生成靜態網站,看看jekyll:http://jekyllrb.com/

你根據一定的目錄結構設置你的文件,並在其上運行jekyll。它處理這些文件並生成HTML頁面。

0

多一點檢查,我不喜歡單個noscript.html頁面。

我的確發現了我需要的Java Server Pages。只需使用「包含文件」等詞語即可包含文件。