views:

122

answers:

4

I have some ten html pages each page also has same header and footer tag can i have one page with complete header and footer ,and i will refer to that particular page from other html pages.

+3  A: 

You do this by using a server side language like PHP or another one of the myriad different languages out there, which pre-processes the page. Something along these lines:

<?php include 'header.html'; ?>

... page contents...

<?php include 'footer.html'; ?>
deceze
Thanks for the reply , is their any way to do on the clientside without using any serverside controls.
mahesh
@mahesh I guess you *could* do it in Javascript if you're so inclined (fetch header and footer files via AJAX, inject into DOM), but I really wouldn't recommend it. You'll also still have to repeat a certain amount of HTML preamble this way anyway.
deceze
I am using asmx webservices on the serverside .
mahesh
You can do this using XSLT on the client. All modern browsers have decent XLST support, including IE6. :)
no
Is thier any way of using contentplaceholder like control which is used in asp.net for html pages
mahesh
+1  A: 

What's your server side scripting language? You can do what is called an "include."

The exact syntax depends on the language(s) your web server supports.

Chris Adragna
I am using webservices on serverside with c# coding,I want my html to be plain without using any asp tags into it is thier any way to do it on the clientside
mahesh
Yes, with XSL include. I have to say it's probably better to do it server side because you know for certain it will get included going to the browser.
Chris Adragna
+1  A: 

Presuming the "master-pages" tag on the question refers to ASP.NET, here's a Super Link. Ps. You should give Ruby on Rails a try as well :)

Zabba
+1  A: 

If you don't care about users who have JavaScript disabled, or are using some mobile platforms, you can use JavaScript to do it.

headerfooter.js

window.onload = function ()
    {
        var header = document.getElementById('header');
        var footer = document.getElementByID('footer');

        header.innerHTML = "<h1>My website</h1><h2>Rules</h2>";
        footer.innerHTML = "<small>This code is in the public domain</small>";
    }

page.html

<html>
  <head>
    <script type="text/javascript" src="headerfooter.js"></script>
  </head>
  <body>
    <div id="header"></div>
    ... Your content ...
    <div id="footer"></div>
  </body>
</html>

But don't do this, it's user unfriendly, and unprofessional. Just stick with either using php, or building a solid template which doesn't need to be edited much later.

Andrew Dunn
Ya can i do with template building
mahesh