複数のページすべてに同じマークアップを追加するのではなく、複数のページで使用されている同一のHTMLをリンクするにはどうすればよいですか。
6 に答える
You can do this using an iframe
on each of the several pages, with the src
being the common HTML.
It also is possible on the client-side using javascript. jQuery makes this particularly easy providing a load
method. You can use jQuery.load()
to add an HTML block into elements across different HTML pages.
As an example, if every one of the pages has an div
named content
:
<div id=`contents`></div>
Then you could do this in each page:
$('#content').load('commonContent.html');
サーバー側から実行できます。
PHPを使用している場合は、を使用できますinclude()
。
JavaScriptを使用して可能ですhttp://webdesign.about.com/od/javascript/ht/htjsincludehtm.htm
You should check: http://www.triadwebcrafters.com/article_server_side_language.cfm and Best practice for inserting large chunks of HTML into elements with Javascript?
Webホストで許可されている場合は、サーバーサイドインクルード(SSI)がそのトリックを実行します。したがって、ファイル「common.htm」のコンテンツを挿入するには、これを各ページのhtmlに挿入するだけです。
<!–-#include virtual="common.htm” -–>
あなたはここでそれについて読むことができます:http://en.wikipedia.org/wiki/Server_Side_Includes
asp.netMVCフレームワークを調べることをお勧めします。異なるページ間で共通の部分を書き込むための共有ビューがあります。