user1535882
user1535882

Reputation: 119

Linking identical HTML over several pages

How would I link identical HTML used in several pages, instead of adding the same markup in all of the several pages.

Upvotes: 4

Views: 6364

Answers (6)

aadarshsg
aadarshsg

Reputation: 2089

You might want to look into asp.net MVC framework. You have a Shared View in it to write the part which is common between different pages.

Upvotes: 0

pb2q
pb2q

Reputation: 59637

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');

Upvotes: 3

yitwail
yitwail

Reputation: 2009

If it's allowed by the web host, server side includes (SSI) will do the trick. So, to insert the contents of a file "common.htm", just put this in the html for each page:

<!–-#include virtual="common.htm” -–>

you can read about it here: http://en.wikipedia.org/wiki/Server_Side_Includes

Upvotes: 1

Alex
Alex

Reputation: 1028

It is possible using JavaScript http://webdesign.about.com/od/javascript/ht/htjsincludehtm.htm

Upvotes: 2

Madara&#39;s Ghost
Madara&#39;s Ghost

Reputation: 175088

It can be done from the server side.

If you're using PHP, you can use include().

Upvotes: 3

Related Questions