1

Can someone guide me how to include html file with an html file. I have been trying to embed my file within object tags but to no avail.

Thanks!

5 Answers 5

4

You can use the iframe tag.
Another option is to used Server Side inclusion using SHTML, this require that the web server support it, see Server Side Includes

Sign up to request clarification or add additional context in comments.

2 Comments

Right! I remeber this one, it exists for years, I used it when I used SSI in late nineties and it has great explanation
the boutell.com link basically says it all.
1

You are quite limited in HTML. You can use iframe tag but it's the same type of embedding as embedding of flash in html pages.

OT: It would be quite easy in PHP. Can you use it? Or do you need static web page?

2 Comments

I am unsure whether server side includes can be used in static html pages at all. I have been trying to do it for quite some time but to no avail. Here's what I have been trying to to my html file which resides within the root of my web. <div> <!--#include virtual="/HtmlObjects/DeliveryEstimator.htm"--> </div> Any help would be appreciated. Thanks.
I don't know about this possibility. There are dynamic html pages and static html pages. I was asking to know what are your limitations. For example, if you want to create a static html in order to burn them on CD/DVD then it is better in my opinion to write a simple script in powershell/bash to do those includes for you.
0

Can you perhaps use Javascript to dynamically load it in?

Comments

0

You can have it loaded via JQuery as shown here: Include another HTML file in a HTML file

a.html:

<html> 
  <head> 
    <script src="jquery.js"></script> 
    <script> 
    $(function{
      $("#includedContent").load("b.html"); 
    });
    </script> 
  </head> 

  <body> 
     <div id="includedContent"></div>
  </body> 
</html>

b.html:

<p> This is my include file </p>

Comments

0

May be this help:

Inside js/utils.js define functions:

function loadFileSync(fileName) {
    var req = new XMLHttpRequest();
    req.open('GET', fileName, false);
    req.send(null);

    if (req.status === 200) {
        //console.log(req.responseText);
        return req.responseText
    } else 
        return "ERROR!!!"
}

function includeFile(fileName) {
    document.write(loadFileSync(fileName))
}

And in main html file add this:

<script src="js/utils.js"></script>

<script> includeFile("navigation.html") </script>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.