0

Suppose I have 3 html files , A.html , B.html and C.html
I want the HTML code from C.html to act as the footer of A.html and B.html .
Currently what I do is write the total contents of C.html in A & B to have my footer.
Is it possible to use just a single code or css-stlye to load the contents of C.html

Suppose C.html looks like --

<a href=k.com>K</a><br>
<a href=b.com>b</a><br>
<a href=d.com>d</a><br>
<b>This page made by me</b>

How to have this code inserted to other files just by using a single code.
Please note that I have seen this Include another HTML file in a HTML file page but the codes seem to not work for me. I can use <iframe> but then it doesn't look pretty.

Community
  • 1
  • 1
Avi
  • 1,281
  • 1
  • 18
  • 28
  • It is not possible in .HTML file. It is possible only in a .shtml file. Btw, I have done that using iFrames and it looks pretty neat. – mohkhan Jun 20 '13 at 06:31
  • Usually it is done by some sort of server side includes or basic JQuery `ajax`+`html` calls. But you just list HTML+CSS - I don't think there is solution with such constraints. – Alexei Levenkov Jun 20 '13 at 06:31
  • Use iframe or JavaScript. If it doesn't look pretty...well it's what CSS are for, no? – Adriano Repetti Jun 20 '13 at 06:32
  • 2
    @mohkhan - The problem with iframe is that I will have to manually specify the `height` and `width` attributes for perfect results. And then If I edit C.html , I will have to change the attributes again, in all the many files – Avi Jun 20 '13 at 06:39
  • @MrLister - I dont understand the term `dialect` in context of HTML. The language is `en`. – Avi Jun 20 '13 at 07:21
  • @AviAryan You have an element named `` in your source, which doesn't exist. – Mr Lister Jun 20 '13 at 08:22
  • @MrLister - Sorry, that was nothing but an example to explain what I need. I dont use that code – Avi Jun 20 '13 at 10:54
  • possible duplicate of [Include another HTML file in a HTML file](http://stackoverflow.com/questions/8988855/include-another-html-file-in-a-html-file) – KatieK Jun 26 '13 at 03:23

3 Answers3

2

If your server supports any server side language (as most web servers does) then you can easily marge files.

// Example in php.
<?php 
    include "a.html";
    include "b.html";
    include "c.html"; 
?>
ippi
  • 8,523
  • 2
  • 32
  • 45
1

In pure HTML it is not possible. Why not use an iFrame? You can then style it as you choose. Or you can use jQuery's load method to pull content into your page.

Gary
  • 11,083
  • 14
  • 43
  • 68
randomizer
  • 1,614
  • 3
  • 14
  • 31
  • I use the 20+, accepted answer provided here at http://stackoverflow.com/questions/8988855/include-another-html-file-in-a-html-file. It doesnt work for me – Avi Jun 20 '13 at 06:41
  • @AviAryan Do you have the library of JQuery available and is it included? – Menno Jun 20 '13 at 06:42
  • @Aquillo - No, I haven't started with JQuery yet ? Where can I get the library and how will I include it – Avi Jun 20 '13 at 06:45
  • @AviAryan Well the answer you're trying to use makes use of JQuery and therefor needs its library. Take a look at the [official website of JQuery](http://jquery.com/). You can download it here, there's also much documentation available on how to get started with JQuery. – Menno Jun 20 '13 at 06:48
  • I thought jQuery was something integrated in Javascript – Avi Jun 20 '13 at 06:54
  • @Aquillo - Still doesnt work. I have downloaded and placed jquery.js in the html files folder , tried it with the give a | b example but it doesnt work. – Avi Jun 20 '13 at 07:09
  • The accepted answer should work. You say you have placed the jquery in the folder, but you have to link it to your htmlpage with script src=... If you did that, check for javascript errors preventing the execution. Maybe you can update your question with the code you have so far? – randomizer Jun 20 '13 at 09:29
  • @randomizer - I am using exactly the same code from the a | b example and the jquery v2.0.1 fromm the site – Avi Jun 20 '13 at 10:52
  • I checked the code and after function the "()" is missing: function(){ ... You also have to run this code on a server, locally it won't work. – randomizer Jun 20 '13 at 11:39
0

Or use a language like PHP to include html parts

atrepp
  • 2,067
  • 1
  • 11
  • 13