2010-04-13 67 views
2

我在我的網站左側有一個聯繫人css選項卡,我有30多頁,我不想在數據發生變化後手動更改所有這些頁面。有誰知道溶劑,所以我只需要修改1個文件來編輯所有頁面?通過更改一個文件來編輯內容的方法?

也許在JavaScript?

下面的代碼是爲選項卡

<div class="slide-out-div"> 
     <a class="handle" href="http://link-for-non-js-users">Content</a> 
     <h3>Onze contact gegevens</h3> 
     <p>Adres: van Ostadestraat 55<br /> 
      Postcode: 8932 JZ<br /> 
     Plaats: Leeuwarden<br /> 
     Tel: 058 844 66 28<br /> 
     Mob: 0629594595 
     <br /> 
     E-mail: <a href="mailto:[email protected]">[email protected]</a><br /><br /> 
     </p> 
<p>Mocht u vragen hebben dan kunt u gerust bij ons terecht voor meer informatie.</p> 

編輯:

這是我的HTML

<!--#include virtual="contact.txt" --> 
    </body> 

,這是在我的contact.txt其中位於腐我的web文件夾:

<div class="slide-out-div"> 
     <a class="handle" href="http://link-for-non-js-users">Content</a> 
     <h3>Onze contact gegevens</h3> 
     <p>Adres: van Ostadestraat 55<br /> 
      Postcode: 8932 JZ<br /> 
     Plaats: Leeuwarden<br /> 
     Tel: 058 844 66 28<br /> 
     Mob: 0629594595 
     <br /> 
     E-mail: <a href="mailto:[email protected]">[email protected]</a><br /><br /> 
     </p> 
<p>Mocht u vragen hebben dan kunt u gerust bij ons terecht voor meer informatie.</p> 
+0

我認爲這是一個問題在我的主機供應商方面,我有一個共享的主機 – Chris 2010-04-13 11:39:41

回答

4

您可能想要使用Server Side Includes(SSI)。

您將使您的代碼段到一個單獨的文件,如contact.txt,然後你就只需使用引用它在所有的30頁:

<!--#include virtual="contact.txt" --> 

SSI是由所有流行的Web服務器支持包括Apache,IIS和lighttpd。

+0

太棒了!謝謝!! – Chris 2010-04-13 11:30:10

+0

由於某種原因,它不起作用,我編輯了我的問題 – Chris 2010-04-13 11:35:16

+0

@Chris:您使用的是什麼Web服務器? SSI可能被禁用...當你從你的網頁瀏覽器打開你的html頁面,然後你點擊'查看源代碼'時,你會發現'<! - #include virtual =「contact.txt」 - >'comment?如果是,SSI被禁用。如果不是,那麼很可能它只是不正確的路徑。 – 2010-04-13 11:38:27

3

使用相關的HTML /文本創建一個文本文件,並將其放到您希望顯示的HTML中。

<!--#include virtual="path to file/include-file.txt" --> 

希望幫助:)

UPDATE:

漫長的討論後,重命名您的網頁.PHP代替.html和你接觸到.PHP代替.txt和用這個來包含你的文件:

<?php include('contact.php'); ?> 

如果您的網頁在不同的目錄,使用:

<?php include($DOCUMENT_ROOT . "/path-to-files/contact.php"); ?> 

這將強制頁面查看您的網站的根目錄。

-2

正如我接受丹尼爾和凱爾解決方案(我+1他們的答案)

如果Iwere inyour情況。我maked與您的聯繫方式一個html,然後包括它的框架到其他30頁像

  • contact.html(其中只包含聯繫信息)
  • page1.htm
  • pagex.htm
  • page30.htm

並在一個pagex中。htm提供以下代碼

<body> 
    Other part of page .... 
    <iframe id="contact" src="../contact.htm"></iframe> 
</body> 
+0

我寧願不使用iframe – Chris 2010-04-13 11:42:00

1

如上所述,您可以使用Apache的SSI。這取決於正在使用的特定網絡服務器和模塊。

爲了達到這種效果,你既可以做兩件事情:

使用某種類型的模板語言的支持它,和「編譯」上傳到Web服務器之前。使用ruby的ERB就是一個例子。

其他就是使用服務器端編程語言(我推薦使用PHP,因爲它很簡單,易於部署和大量的文檔)可以在服務器上爲您完成。

下面是使用PHP的一個簡單的例子:http://www.albinoblacksheep.com/tutorial/include