FRIHOSTFORUMSSEARCHFAQTOSBLOGSCOMPETITIONS
You are invited to Log in or Register a free Frihost Account!


.html using header/footer include script?





Mumpay
hey all,

I have a client's site that was built all in HTML (aka dreamweaver Rolling Eyes )

They have a footer on every page, that is hard coded on the pages themselves.

So when they want to change the footer, every single page needs to be updated.

Is there a way to use some sort of include script from a single footer.inc file, but keep the pages with their .html extensions?


Thanks!
Nyizsa
I don't know of such a tag, but there are several solutions.
1. Use PHP. You can keep the .html extension, just make sure that they are parsed. This will enable them for upgrade their site in the future.
2. Use an iframe. It will look a bit strange, but it will work.
3. Use frameset pages. I don't really suggest this, as the whole site has to be re-designed, and frames are not for this purpose anyway. Not to mention that they are search-engine-unfriendly.
So, the decision is yours...
mathiaus
avoid frames and use php.

include
Code:
<?php include('path/directory/folder/footer.extension'); ?>



.htaccess code to make php parse html files
Code:
AddHandler application/x-httpd-php .html

Of course renaming all the files to a .php would be better Smile
adhoc
If you don't have access to server-side stuff, you could simply use Javascript.

Put the footer in footer.html

In your pages just put:
<script type="text/javascript" src="footer.js"></script>

And in footer.js you output the footer. Here's an example I dug up somewhere.. Might work, I don't know.

Code:

var req = null;

if (window.XMLHttpRequest)
   req = new XMLHttpRequest ();
else if (window.ActiveXObject)
   req  = new ActiveXObject (Microsoft.XMLHTTP);

req.onreadystatechange = function()
{
   if(req.readyState == 4 && req.status == 200)
      document.write (req.responseText);
};

req.open("GET", "footer.html", true);
req.send(null);
Stubru Freak
adhoc wrote:
If you don't have access to server-side stuff, you could simply use Javascript.

Put the footer in footer.html

In your pages just put:
<script type="text/javascript" src="footer.js"></script>

And in footer.js you output the footer. Here's an example I dug up somewhere.. Might work, I don't know.

Code:

var req = null;

if (window.XMLHttpRequest)
   req = new XMLHttpRequest ();
else if (window.ActiveXObject)
   req  = new ActiveXObject (Microsoft.XMLHTTP);

req.onreadystatechange = function()
{
   if(req.readyState == 4 && req.status == 200)
      document.write (req.responseText);
};

req.open("GET", "footer.html", true);
req.send(null);


This uses AJAX which isn't supported by some old browsers, and people with javascript turned off.

Maybe try SSI
adhoc
Stubru Freak wrote:
adhoc wrote:
If you don't have access to server-side stuff, you could simply use Javascript.


This uses AJAX which isn't supported by some old browsers, and people with javascript turned off.


A minority so small that it can easily be ignored. But, yes, of course: SSI, if availible, is much better.
Stubru Freak
adhoc wrote:
Stubru Freak wrote:
adhoc wrote:
If you don't have access to server-side stuff, you could simply use Javascript.


This uses AJAX which isn't supported by some old browsers, and people with javascript turned off.


A minority so small that it can easily be ignored. But, yes, of course: SSI, if availible, is much better.


That minority is bigger then you might think.
And still it's better to do:
<script type="text/javascript" src="footer.js"></script>

And then document.write what you want in footer.js

It's easier to implement then AJAX, faster, more widely supported, also the browser will still show loading if the footer isn't loaded yet (in contrary to AJAX where the browser will say Loaded even if you didn't load the footer yet which confuses people)

AJAX is useful if needed but it is abused too much lately.
adhoc
Stubru Freak wrote:
adhoc wrote:
Stubru Freak wrote:
adhoc wrote:
If you don't have access to server-side stuff, you could simply use Javascript.


This uses AJAX which isn't supported by some old browsers, and people with javascript turned off.


A minority so small that it can easily be ignored. But, yes, of course: SSI, if availible, is much better.


That minority is bigger then you might think.


Really? I've been a big fan of making everything backwards compatible -- it's nice to be a purist, but, frankly, recently I've found that it's mostly been a waste of time.

Stubru Freak wrote:
And still it's better to do:
<script type="text/javascript" src="footer.js"></script>

And then document.write what you want in footer.js

It's easier to implement then AJAX, faster, more widely supported, also the browser will still show loading if the footer isn't loaded yet (in contrary to AJAX where the browser will say Loaded even if you didn't load the footer yet which confuses people)

AJAX is useful if needed but it is abused too much lately.


I thought of recommending document.write first, but I decided against it. What makes you say that it's easier to implement? On the contrary, he would have to escape all his footer data so that it would fit into the javascript string. It would be ugly-unreadable and much harder to maintain in the future. I don't see why it would be much faster either. All the extra escaping and the possibly numerous document.writes would just add unnecessary overhead to load. I suppose document.write is more widely supported, but if his visitors are running a browser with javascript at all, they most likely have xmlhttprequest too. With all the virus scares, a lot of people are running modern browsers... or they're not running at all.

This is not a big issue. It's just that I would choose the simpler way first. You wouldn't gain much speed from using just document.write, but you would lose a lot in simplicity and maintainability. Computer time is much cheaper than programmer time..
Stubru Freak
adhoc wrote:
Stubru Freak wrote:
adhoc wrote:
Stubru Freak wrote:
adhoc wrote:
If you don't have access to server-side stuff, you could simply use Javascript.


This uses AJAX which isn't supported by some old browsers, and people with javascript turned off.


A minority so small that it can easily be ignored. But, yes, of course: SSI, if availible, is much better.


That minority is bigger then you might think.


Really? I've been a big fan of making everything backwards compatible -- it's nice to be a purist, but, frankly, recently I've found that it's mostly been a waste of time.

Stubru Freak wrote:
And still it's better to do:
<script type="text/javascript" src="footer.js"></script>

And then document.write what you want in footer.js

It's easier to implement then AJAX, faster, more widely supported, also the browser will still show loading if the footer isn't loaded yet (in contrary to AJAX where the browser will say Loaded even if you didn't load the footer yet which confuses people)

AJAX is useful if needed but it is abused too much lately.


I thought of recommending document.write first, but I decided against it. What makes you say that it's easier to implement? On the contrary, he would have to escape all his footer data so that it would fit into the javascript string. It would be ugly-unreadable and much harder to maintain in the future. I don't see why it would be much faster either. All the extra escaping and the possibly numerous document.writes would just add unnecessary overhead to load. I suppose document.write is more widely supported, but if his visitors are running a browser with javascript at all, they most likely have xmlhttprequest too. With all the virus scares, a lot of people are running modern browsers... or they're not running at all.

This is not a big issue. It's just that I would choose the simpler way first. You wouldn't gain much speed from using just document.write, but you would lose a lot in simplicity and maintainability. Computer time is much cheaper than programmer time..


You can escape the whole thing with a simple search and replace (two search and replaces if you have line breaks) and put it all in one document.write, and you can get the original back by just reversing the search and replace.

AJAX really gives the impression to take longer to load (not really, but as you know perceived speed is more important then real speed) because of the browser saying the document is loaded when in fact it is not. People get annoyed by an extra waiting time after that.
adhoc
Stubru Freak wrote:
You can escape the whole thing with a simple search and replace (two search and replaces if you have line breaks) and put it all in one document.write, and you can get the original back by just reversing the search and replace.

AJAX really gives the impression to take longer to load (not really, but as you know perceived speed is more important then real speed) because of the browser saying the document is loaded when in fact it is not. People get annoyed by an extra waiting time after that.


That might be true.. As AJAX has become really popular lately, browsers should fix that.
Mumpay
interesting discussion on javascript guys!

however, the client has a footer with all their links simply as a backup to their javascript popout menu. So people can still get to pages even if the main flyout menu doesn't work due to javascript being disabled. Sooooo.. probably wouldn't make sense to also put the backup to javascript IN javascript, hmm....

I tried the SSI (php) bit though, so far no dice with the .httaccess file. But, they have over 80 folders (such a messy site, so bad, I didn't make it, I swear. It's just terrible, lol). So since the .htaccess file would have to be in every directory.... ouch....

I sent the client an email to tell whoever runs the server to do this:

http://www.spiderpro.com/bu/buphph001.html

Quote:
The trick to achieve this is to add a mimetype. If you have access to the configuration file (httpd.conf for Apache) you need to add a line:
AddType application/x-httpd-php .php .html


I won't hear back on that idea for likely a few days though, so now I just gotta wait...
Related topics
Reply to topic    Frihost Forum Index -> Scripting -> Html, CSS and Javascript

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.